Add JS code to header tag of html

Reading docs about drupal_add_js you might think you can add JS to header of html, but only thing you can choose is header or footer of your theme (as region), to add JS to header tag, you need to use 

How many database tables do nodes and entities produce depending on settings

In this post I will determine how many DB tables does each option you choose make.
 

Lets start with NODE, make a basic node, with just title and body, when we enter data for it, it will populare 6 tables.

1. node
2. node_revision
3. node__body
4. node_revision__body
5. node_field_data
6. node_field_revision

How to encode json with drupal_http_request in drupal 7

In lots of places you will see how to use drupal_http_request with drupal_http_build_query used on data, which is fine if you want to build regular query data (like the ones you have in URLs when using GET) but if you want to send JSON, you shouldn't use that, instead you need  json_encode function on data.

Solr search, where to find body field

By default body field of a content type will not be shown among the fields to index, which is kind of strange but that is how it is as many other properties and fields of content are there by default.

Using try catch - php exceptions

Not many devs use try catch in custom code, especially in drupal 7. Thing is that it can save you from bigger problems if you wrap your (bad) code into that block, so lets just make simple example how to use it.

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

 

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.