Commit 8f1c7a8c authored by catch's avatar catch
Browse files

Issue #2616814 by dpi, Xano, geek-merlin, Hardik_Patel_12, jofitz, alexpott,...

Issue #2616814 by dpi, Xano, geek-merlin, Hardik_Patel_12, jofitz, alexpott, Fabianx, catch, joachim, andypost, dawehner, daffie, cweagans, neclimdul: Delegate all hook invocations to ModuleHandler

(cherry picked from commit 9d6e87930b63050f592f02ed4eb68717afefe915)
parent 9a265629
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -312,10 +312,9 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize) {
      if ($settings_required && $settings_have_changed) {
        $settings = $this->getJsSettingsAssets($assets);
        // Allow modules to add cached JavaScript settings.
        foreach ($this->moduleHandler->getImplementations('js_settings_build') as $module) {
          $function = $module . '_js_settings_build';
          $function($settings, $assets);
        }
        $this->moduleHandler->invokeAllWith('js_settings_build', function (callable $hook, string $module) use (&$settings, $assets) {
          $hook($settings, $assets);
        });
      }
      $settings_in_header = in_array('core/drupalSettings', $header_js_libraries);
      $this->cache->set($cid, [$js_assets_header, $js_assets_footer, $settings, $settings_in_header], CacheBackendInterface::CACHE_PERMANENT, ['library_info']);
+1 −1
Original line number Diff line number Diff line
@@ -366,7 +366,7 @@ protected function parseLibraryInfo($extension, $path) {

    // Allow modules to add dynamic library definitions.
    $hook = 'library_info_build';
    if ($this->moduleHandler->implementsHook($extension, $hook)) {
    if ($this->moduleHandler->hasImplementations($hook, $extension)) {
      $libraries = NestedArray::mergeDeep($libraries, $this->moduleHandler->invoke($extension, $hook));
    }

+3 −4
Original line number Diff line number Diff line
@@ -229,8 +229,7 @@ protected function invokeCronHandlers() {
    $logger = $time_logging_enabled ? $this->logger : new NullLogger();

    // Iterate through the modules calling their cron handlers (if any):
    foreach ($this->moduleHandler->getImplementations('cron') as $module) {

    $this->moduleHandler->invokeAllWith('cron', function (callable $hook, string $module) use (&$module_previous, $logger) {
      if (!$module_previous) {
        $logger->info('Starting execution of @module_cron().', [
          '@module' => $module,
@@ -247,7 +246,7 @@ protected function invokeCronHandlers() {

      // Do not let an exception thrown by one module disturb another.
      try {
        $this->moduleHandler->invoke($module, 'cron');
        $hook();
      }
      catch (\Exception $e) {
        watchdog_exception('cron', $e);
@@ -255,7 +254,7 @@ protected function invokeCronHandlers() {

      Timer::stop('cron_' . $module);
      $module_previous = $module;
    }
    });
    if ($module_previous) {
      $logger->info('Execution of @module_previous_cron() took @time.', [
        '@module_previous' => $module_previous,
+12 −8
Original line number Diff line number Diff line
@@ -862,15 +862,19 @@ protected function invokeTranslationHooks(ContentEntityInterface $entity) {
  protected function invokeStorageLoadHook(array &$entities) {
    if (!empty($entities)) {
      // Call hook_entity_storage_load().
      foreach ($this->moduleHandler()->getImplementations('entity_storage_load') as $module) {
        $function = $module . '_entity_storage_load';
        $function($entities, $this->entityTypeId);
      $this->moduleHandler()->invokeAllWith(
        'entity_storage_load',
        function (callable $hook, string $module) use (&$entities) {
          $hook($entities, $this->entityTypeId);
        }
      );
      // Call hook_TYPE_storage_load().
      foreach ($this->moduleHandler()->getImplementations($this->entityTypeId . '_storage_load') as $module) {
        $function = $module . '_' . $this->entityTypeId . '_storage_load';
        $function($entities);
      $this->moduleHandler()->invokeAllWith(
        $this->entityTypeId . '_storage_load',
        function (callable $hook, string $module) use (&$entities) {
          $hook($entities);
        }
      );
    }
  }

+6 −4
Original line number Diff line number Diff line
@@ -342,10 +342,12 @@ public function fieldAccess($operation, FieldDefinitionInterface $field_definiti
    // Invoke hook and collect grants/denies for field access from other
    // modules.
    $grants = [];
    $hook_implementations = $this->moduleHandler()->getImplementations('entity_field_access');
    foreach ($hook_implementations as $module) {
      $grants[] = [$module => $this->moduleHandler()->invoke($module, 'entity_field_access', [$operation, $field_definition, $account, $items])];
    $this->moduleHandler()->invokeAllWith(
      'entity_field_access',
      function (callable $hook, string $module) use ($operation, $field_definition, $account, $items, &$grants) {
        $grants[] = [$module => $hook($operation, $field_definition, $account, $items)];
      }
    );
    // Our default access flag is masked under the ':default' key.
    $grants = array_merge([':default' => $default], ...$grants);

Loading