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

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);


Configure git to ignore some files locally without .gitignore file

Some times you dont want to add something to .gitignore, while it would be nice that there is some .gitignore-local version by default, there is not, so you need to find a different way to do this, the way to do is this.  Go to .git/info/exclude file and edit it like regular .gitignore file, add files/folders you want to ignore.

Xdebug and docker4drupal on mac

To have xdebug working, you need to have this in your docker config for PHP.

      PHP_XDEBUG: 1
      PHP_XDEBUG_REMOTE_HOST: # macOS, Docker < 18.03

Also it is often noted that this should also be run

Making url with anchor(fragment) and making url with query string appended

$options = ['fragment' => 'feedback'];
$url = Url::fromRoute('entity.node.canonical', ['node' => 22], $options);

$options = ['query' => ['animal' => 'dog', 'color' => 'black']];
$url = Url::fromRoute('entity.node.canonical', ['node' => 42], $options);

So first would give you  this result 

Some ways to make links in drupal 8

// Link to an internal path defined by a route.
$link = Link::createFromRoute('This is some link', 'entity.node.canonical', ['node' => 22])

// Link to an external URI.
$link = Link::fromTextAndUrl('This is a link', Url::fromUri(''));

// Get output as a render array.

// Get output as a string.