Drupal Dump

Drupal Snippets, Hacks and more....

Deploying big release branches, steps to take (dry run merge and checkup)

If you have big sprint with big amount of task and put all of that into feature branch that you need to deploy (merge to master) then it is good to have one big final checkup before doing that. So what I do is this, go to your master branch and either make one temp branch from it like "master_temp" or do it directly there. For extra caution I use temp branch.

Use file_scan_directory and sort files in array

If you are using file_scan_directory to scan files in some directory and then loop over them to use them for some action, you probably also want to sort them, otherwise you will get them in order that is set in filesystem. So to do that, you need to set key in options to "filename" to use filename as key, so you can sort that associative array per key.

Flush image styles in drupal 7

To flush some image style, you can install module for that with UI, but you can also do it in lean way, with just drush php command or if locally with devel/php window. If using drush use this command

 drush php-eval '$style = image_style_load("optimize_original"); image_style_flush($style);'


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.