Change record status: 
Project: 
Introduced in branch: 
8.4.x
Introduced in version: 
Description: 

hook_theme() implementations currently return an associative array. The top-level keys are the names of theme hooks, and their values are arrays with a series of magic keys describing the theme hook (template name, path, preprocess functions, etc.)

A new \Drupal\Core\Theme\ThemeHook class can now be used instead of an array.

Before:

function mymodule_theme() {
  $items = [];
  $items['my_theme_hook'] = [
    'function' => 'mymodule_custom_theme_function',
    'variables' => ['foo' => NULL],
  ];
  return $items;
}

After:

function mymodule_theme() {
  $items = [];
  $items[] = ThemeHook::create('my_theme_hook')
    ->setFunction('mymodule_custom_theme_function')
    ->setVariables(['foo' => NULL]);
  return $items;
}
Impacts: 
Module developers
Themers