Logging arrays with logger

In drupal 8 for logging we use logger service, to log array data in some readable format, you should use little hack like in drupal 7 adding html code and print_r to array.

Dependency injection and constructors - what really happens

use Drupal\Core\Controller\ControllerBase;
use Drupal\my_module\SomeClass;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;

class SomeController extends ControllerBase
{
    private $someProperty;

    public function __construct(SomeClass $someProperty)
    {

Drupal 8 - getting what is what

Getting into drupal 8 from drupal 7 is hard. Especially if you are new to OOP, some articles about what is what will help you on that way. I suggest the following in that order

Drilling data from entities in drupal 8

Still new to this drupal 8 beast and trying to learn how to drill down data from entites. There are this magic getters and setters methods that get you data without need to write them. So

Messages api, make message programmatically for orders

I wanted to add a message to orders when I did some auto approving of orders. To add some trace of that you need to load user which will be the one that did that. Send $values that will be used for token replacement in message and also select which message type you are going to use. In here I made a clone of default message "commerce_order_admin_comment" and used that.

Get list of all the hooks your site currently uses

In includes/module.inc, find the module_implements() function (around line 715 in Drupal 7). At the top of the function, just add this below and you will get huge output of all the hooks that are called.

 

function module_implements($hook, $sort = FALSE, $reset = FALSE) {
  drupal_set_message("hook_$hook");
  ......

 

Find out which theme function to call to alter each element on page

This is a hack on how to get output of which theme function to call to alter each element on page. So you will need to go to In includes/theme.inc in the Drupal 7 theme() function, around line 1161 and change $output from one line to two lines and to have this code below. You will get theme suggestions all around the page, which will be messy but will help you find what you need.