Drupal Dump

Drupal Snippets, Hacks and more....

495 posts since 2011

Migrations in Drupal 8, what is it all about

Migrations and migration api came as surprise to me, really powerful stuff. It can be used as a tool for one of import of whatever content you might have or for continuous import of some data from any endpoint. With core import module, for proper framework I would suggest adding migrate tools and migrate plus modules. 

Get translated value of particular taxonomy term

First get current language

$language =  \Drupal::languageManager()->getCurrentLanguage(\Drupal\Core\Language\LanguageInterface::TYPE_CONTENT)->getId();

then load term with providing term id

Orphaned migration config breaks migration UI

If you created some migration config and then you renamed it later, there is a good chance it is still present in config and it can also break your migration UI for that migration group. To clear that out, check your config with drush cedit find id of config and run this in devel/php or drush php

Fetch your mysql configuration

You want to check some environment variables values for your current setup. Log into mysql and type something like

What to use, text list or taxonomy term?

To force users or administrators to have predefined list of what to put into some field you will need to use one of this 2 solutions, text list or taxonomy term reference field. 

Cannot save files in PHPStorm

Maybe you came to that annoying message when you want to save something in PHP Storm but it refuses to and gives you options "cancel" or "revert changes", usually happens around some config files, like settings.php. Why is this so? Probably because you didn't put write permissions to folder where phpstorm is trying to write its temp files.

Get values from $settings variable

When you set or override some variables in settings.php with $settings var and want to get it in your code, call it like this.

 

use Drupal\Core\Site\Settings;

$mySetting = Settings::get('some_setting', NULL);

 

Testing drupal site as authenticated user

In order to generate authenticated requests using curl we can use the session cookie from a session in our browser. How to find that? Sign in to your site in your browser. Then find the cookie that starts with either SESS, or SSESS followed by a random string.