function HookCollectorKeyValueWritePass::process

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Hook/HookCollectorKeyValueWritePass.php \Drupal\Core\Hook\HookCollectorKeyValueWritePass::process()

File

core/lib/Drupal/Core/Hook/HookCollectorKeyValueWritePass.php, line 26

Class

HookCollectorKeyValueWritePass
Stores hook implementations in keyvalue and clears cache.

Namespace

Drupal\Core\Hook

Code

public function process(ContainerBuilder $container) : void {
  $hookData = $container->getParameter('.hook_data');
  if ($container->hasParameter('.theme_hook_data')) {
    $themeHookData = $container->getParameter('.theme_hook_data');
    $hookData = array_merge($hookData, $themeHookData);
    $hookData['preprocess_for_suggestions'] = array_merge($hookData['preprocess_for_suggestions'], $hookData['theme_preprocess_for_suggestions']);
  }
  $keyvalue = $container->get('keyvalue')
    ->get('hook_data');
  assert($keyvalue instanceof KeyValueStoreInterface);
  $keyvalue->setMultiple($hookData);
  $container->get('cache.bootstrap')
    ->deleteMultiple([
    'hook_data',
    'theme_hook_data',
  ]);
  // Remove converted flags, they are only needed while building the
  // container.
  $parameters = $container->getParameterBag();
  foreach ($parameters->all() as $name => $value) {
    if (str_ends_with($name, '.skip_procedural_hook_scan')) {
      $parameters->remove($name);
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.