Commit 787dcbc2 authored by catch's avatar catch
Browse files

Issue #3490298 by nicxvan: Profiles can be missed in OOP hooks

(cherry picked from commit 6cc34e19)
parent 8e65c4ce
Loading
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -169,9 +169,9 @@ protected function collectModuleHookImplementations($dir, $module, $module_preg)
      $extension = $fileinfo->getExtension();
      $filename = $fileinfo->getPathname();

      if ($extension === 'module' && !$iterator->getDepth()) {
        // There is an expectation for all modules to be loaded. However,
        // .module files are not supposed to be in subdirectories.
      if (($extension === 'module' || $extension === 'profile') && !$iterator->getDepth()) {
        // There is an expectation for all modules and profiles to be loaded.
        // .module and .profile files are not supposed to be in subdirectories.
        include_once $filename;
      }
      if ($extension === 'php') {
+23 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\testing_hooks\Hook;

use Drupal\Core\Hook\Attribute\Hook;

/**
 * Hook implementation on behalf of another module.
 */
class TestingHooksProfile {

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

}
+10 −0
Original line number Diff line number Diff line
name: Testing Hooks in profile
type: profile
description: 'Minimal profile for running tests. Includes absolutely required modules only.'
version: VERSION
hidden: true
install:
  # Enable page_cache and dynamic_page_cache in testing, to ensure that as many
  # tests as possible run with them enabled.
  - drupal:page_cache
  - dynamic_page_cache
+18 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Implement hooks.
 */

declare(strict_types=1);

/**
 * This implements cache_flush.
 *
 * We do not have implements so this does not get converted.
 */
function testing_hooks_cache_flush(): void {
  // Set a global value we can check in test code.
  $GLOBALS['profile_procedural'] = 'profile_procedural';
}
+37 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\FunctionalTests\Installer;

use Drupal\Tests\BrowserTestBase;

/**
 * Tests installing the Testing profile with update notifications on.
 *
 * @group Installer
 */
class TestingProfileHooks extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected $profile = 'testing_hooks';

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * Test hooks are picked up.
   */
  public function testHookPickup(): void {
    $this->assertFalse(isset($GLOBALS['profile_procedural']));
    $this->assertFalse(isset($GLOBALS['profile_oop']));
    drupal_flush_all_caches();
    $this->assertTrue(isset($GLOBALS['profile_procedural']));
    $this->assertTrue(isset($GLOBALS['profile_oop']));
  }

}