Traits

Dependency Injection with Traits in Drupal 8

Amber Himes Matz writes on how to discover traits using PHP Storm, but what she finds is useful to know for all Drupal 8 developers. This is the code she was writing:

$url = Url::fromRoute('form_fun.cake_page');
$text = 'Death, or cake? (The basics)';
$links[] = \Drupal::l(t($text), $url);

But by poking in Drupal she finds out she can actually write:

$links[] = $this->l($this->t('Death, or cake? (The basics)'), new Url('form_fun.cake_page'));

Read the article to find out why and how this works.