Commit c3881aff authored by catch's avatar catch
Browse files

Issue #3491386 by nicxvan: Using hooks_converted container parameter changes...

Issue #3491386 by nicxvan: Using hooks_converted container parameter changes $dir during hook collection breaking collection of oop hooks.

(cherry picked from commit f4f0b14b)
parent ee4378d7
Loading
Loading
Loading
Loading
Loading
+52 −59
Original line number Diff line number Diff line
@@ -168,12 +168,6 @@ protected function collectModuleHookImplementations($dir, $module, $module_preg,
    $hook_file_cache = FileCacheFactory::get('hook_implementations');
    $procedural_hook_file_cache = FileCacheFactory::get('procedural_hook_implementations:' . $module_preg);

    // Check only hook classes.
    if ($skip_procedural) {
      $dir = $dir . '/src/Hook';
    }

    if (is_dir($dir)) {
    $iterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::FOLLOW_SYMLINKS);
    $iterator = new \RecursiveCallbackFilterIterator($iterator, static::filterIterator(...));
    $iterator = new \RecursiveIteratorIterator($iterator);
@@ -186,7 +180,7 @@ protected function collectModuleHookImplementations($dir, $module, $module_preg,
      if (($extension === 'module' || $extension === 'profile') && !$iterator->getDepth() && !$skip_procedural) {
        // There is an expectation for all modules and profiles to be loaded.
        // .module and .profile files are not supposed to be in subdirectories.

        // These need to be loaded even if the module has no procedural hooks.
        include_once $filename;
      }
      if ($extension === 'php') {
@@ -239,7 +233,6 @@ protected function collectModuleHookImplementations($dir, $module, $module_preg,
      }
    }
  }
  }

  /**
   * Filter iterator callback. Allows include files and .php files in src/Hook.
+5 −0
Original line number Diff line number Diff line
@@ -16,3 +16,8 @@ function hook_collector_skip_procedural_cache_flush(): void {
  // Set a global value we can check in test code.
  $GLOBALS['skip_procedural_all'] = 'skip_procedural_all';
}

function hook_collector_skip_procedural_custom_function(): void {
  // Set a global value we can check in test code.
  $GLOBALS['test_run'] = 'test_run';
}
+24 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\hook_collector_skip_procedural\Hook;

use Drupal\Core\Hook\Attribute\Hook;

/**
 * Hook implementations for hook_collector_skip_procedural.
 */
class SkipProceduralHooks {

  /**
   * Implements hook_cache_flush().
   */
  #[Hook('cache_flush')]
  public function cacheFlush(): void {
    // Set a global value we can check in test code.
    hook_collector_skip_procedural_custom_function();
    $GLOBALS['skipped_procedural_oop_cache_flush'] = 'skipped_procedural_oop_cache_flush';
  }

}
+2 −1
Original line number Diff line number Diff line
@@ -114,12 +114,13 @@ public function testProceduralHooksSkippedWhenConfigured(): void {
    $this->assertFalse(isset($GLOBALS['procedural_attribute_skip_has_attribute']));
    $this->assertFalse(isset($GLOBALS['procedural_attribute_skip_after_attribute']));
    $this->assertFalse(isset($GLOBALS['procedural_attribute_skip_find']));
    $this->assertFalse(isset($GLOBALS['skipped_procedural_oop_cache_flush']));
    drupal_flush_all_caches();
    $this->assertFalse(isset($GLOBALS['skip_procedural_all']));
    $this->assertFalse(isset($GLOBALS['procedural_attribute_skip_has_attribute']));
    $this->assertFalse(isset($GLOBALS['procedural_attribute_skip_after_attribute']));
    // This is the only one that should be found.
    $this->assertTrue(isset($GLOBALS['procedural_attribute_skip_find']));
    $this->assertTrue(isset($GLOBALS['skipped_procedural_oop_cache_flush']));

  }