Unverified Commit 59f1bee0 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3524716 by nicxvan, catch: [11.1] update gather rules to manage hook preprocess

parent 80dbf1cb
Loading
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -95,6 +95,10 @@ public function process(ContainerBuilder $container): void {
      }
      $priority = 0;
      foreach ($moduleImplements as $module => $v) {
        if (str_starts_with((string) $hook, 'preprocess') && !function_exists($module . '_' . $hook)) {
          $missingProcedural = $module . '_' . $hook;
          @trigger_error("To support Drupal 11.1 the hook $missingProcedural requires the procedural LegacyHook implementation.", E_USER_WARNING);
        }
        foreach ($collector->implementations[$hook][$module] as $class => $method_hooks) {
          if ($container->has($class)) {
            $definition = $container->findDefinition($class);
@@ -382,7 +386,7 @@ public static function checkForProceduralOnlyHooks(Hook $hook, string $class): v
      'hook_install_tasks_alter',
    ];

    if (in_array($hook->hook, $staticDenyHooks) || preg_match('/^(post_update_|preprocess_|update_\d+$)/', $hook->hook)) {
    if (in_array($hook->hook, $staticDenyHooks) || preg_match('/^(post_update_|update_\d+$)/', $hook->hook)) {
      throw new \LogicException("The hook $hook->hook on class $class does not support attributes and must remain procedural.");
    }
  }
+14 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Test preprocess with function does not throw exception.
 */

declare(strict_types=1);

/**
 * @file
 */

function hook_collector_hook_attribute_preprocess_test(): void {}
+22 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\hook_collector_hook_attribute\Hook;

use Drupal\Core\Hook\Attribute\Hook;

/**
 * Test Hook attribute for preprocess.
 */
class PreprocessHook {

  /**
   * Implements hook_cache_flush().
   */
  #[Hook('preprocess_test')]
  public function preprocess(): void {
    $GLOBALS['preprocess'] = 'preprocess';
  }

}
+5 −0
Original line number Diff line number Diff line
name: 'Test Hook preprocess no function in 11.1'
type: module
description: 'Test exception'
package: Testing
version: VERSION
+22 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\hook_collector_preprocess_no_function\Hook;

use Drupal\Core\Hook\Attribute\Hook;

/**
 * Test Hook attribute for preprocess.
 */
class PreprocessHook {

  /**
   * Implements hook_cache_flush().
   */
  #[Hook('preprocess_test')]
  public function preprocess(): void {
    $GLOBALS['preprocess'] = 'preprocess';
  }

}
Loading