Skip to content
Snippets Groups Projects
Commit c2b58306 authored by catch's avatar catch
Browse files

Issue #3523109 by ghost of drupal past, donquixote, nicxvan, dww, larowlan,...

Issue #3523109 by ghost of drupal past, donquixote, nicxvan, dww, larowlan, quietone: Remove support for extending #[Hook] and remove classes extending it #[FormAlter] and #[Preprocess]
parent 4cf0fed2
Branches
Tags
4 merge requests!12628#3524738 backport without deprecation,!12477#3532243: JSON support status during updates,!5423Draft: Resolve #3329907 "Test2",!3478Issue #3337882: Deleted menus are not removed from content type config
Pipeline #497795 passed with warnings
Pipeline: drupal

#497822

    Pipeline: drupal

    #497819

      Pipeline: drupal

      #497817

        +4
        Showing
        with 20 additions and 119 deletions
        <?php
        declare(strict_types=1);
        namespace Drupal\Core\Hook\Attribute;
        use Drupal\Core\Hook\Order\OrderInterface;
        /**
        * Hook attribute for FormAlter.
        *
        * @see hook_form_alter().
        */
        #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
        class FormAlter extends Hook {
        /**
        * {@inheritdoc}
        */
        public const string PREFIX = 'form';
        /**
        * {@inheritdoc}
        */
        public const string SUFFIX = 'alter';
        /**
        * Constructs a FormAlter attribute object.
        *
        * @param string $form_id
        * (optional) The ID of the form that this implementation alters.
        * If this is left blank then `form_alter` is the hook that is registered.
        * @param string $method
        * (optional) The method name. If this attribute is on a method, this
        * parameter is not required. If this attribute is on a class and this
        * parameter is omitted, the class must have an __invoke() method, which is
        * taken as the hook implementation.
        * @param string|null $module
        * (optional) The module this implementation is for. This allows one module
        * to implement a hook on behalf of another module. Defaults to the module
        * the implementation is in.
        * @param \Drupal\Core\Hook\Order\OrderInterface|null $order
        * (optional) Set the order of the implementation.
        */
        public function __construct(
        string $form_id = '',
        public string $method = '',
        public ?string $module = NULL,
        public ?OrderInterface $order = NULL,
        ) {
        parent::__construct($form_id, $method, $module, $order);
        }
        }
        ......@@ -97,28 +97,11 @@
        #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
        class Hook implements HookAttributeInterface {
        /**
        * The hook prefix such as `form`.
        *
        * @var string
        */
        public const string PREFIX = '';
        /**
        * The hook suffix such as `alter`.
        *
        * @var string
        */
        public const string SUFFIX = '';
        /**
        * Constructs a Hook attribute object.
        *
        * @param string $hook
        * The short hook name, without the 'hook_' prefix.
        * $hook is only optional when Hook is extended and a PREFIX or SUFFIX is
        * defined. When using the [#Hook] attribute directly $hook is required.
        * See Drupal\Core\Hook\Attribute\Preprocess.
        * @param string $method
        * (optional) The method name. If this attribute is on a method, this
        * parameter is not required. If this attribute is on a class and this
        ......@@ -132,15 +115,10 @@ class Hook implements HookAttributeInterface {
        * (optional) Set the order of the implementation.
        */
        public function __construct(
        public string $hook = '',
        public string $hook,
        public string $method = '',
        public ?string $module = NULL,
        public ?OrderInterface $order = NULL,
        ) {
        $this->hook = implode('_', array_filter([static::PREFIX, $hook, static::SUFFIX]));
        if ($this->hook === '') {
        throw new \LogicException('The Hook attribute or an attribute extending the Hook attribute must provide the $hook parameter, a PREFIX or a SUFFIX.');
        }
        }
        ) {}
        }
        <?php
        declare(strict_types=1);
        namespace Drupal\Core\Hook\Attribute;
        /**
        * Attribute for defining a class method as a preprocess function.
        *
        * Pass no arguments for hook_preprocess `#[Preprocess]`.
        * For `hook_preprocess_HOOK` pass the `HOOK` without the `hook_preprocess`
        * portion `#[Preprocess('HOOK')]`.
        *
        * See \Drupal\Core\Hook\Attribute\Hook for additional information.
        */
        #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
        class Preprocess extends Hook {
        /**
        * {@inheritdoc}
        */
        public const string PREFIX = 'preprocess';
        }
        ......@@ -2,7 +2,7 @@
        namespace Drupal\comment\Hook;
        use Drupal\Core\Hook\Attribute\Preprocess;
        use Drupal\Core\Hook\Attribute\Hook;
        /**
        * Hook implementations for comment.
        ......@@ -12,7 +12,7 @@ class CommentThemeHooks {
        /**
        * Implements hook_preprocess_HOOK() for block templates.
        */
        #[Preprocess('block')]
        #[Hook('preprocess_block')]
        public function preprocessBlock(&$variables): void {
        if ($variables['configuration']['provider'] == 'comment') {
        $variables['attributes']['role'] = 'navigation';
        ......
        ......@@ -4,7 +4,7 @@
        namespace Drupal\comment_empty_title_test\Hook;
        use Drupal\Core\Hook\Attribute\Preprocess;
        use Drupal\Core\Hook\Attribute\Hook;
        /**
        * Hook implementations for comment_empty_title_test.
        ......@@ -14,7 +14,7 @@ class CommentEmptyTitleTestThemeHooks {
        /**
        * Implements hook_preprocess_comment().
        */
        #[Preprocess('comment')]
        #[Hook('preprocess_comment')]
        public function preprocessComment(&$variables): void {
        $variables['title'] = '';
        }
        ......
        ......@@ -4,7 +4,7 @@
        use Drupal\Core\Config\ConfigFactoryInterface;
        use Drupal\Core\Form\FormStateInterface;
        use Drupal\Core\Hook\Attribute\FormAlter;
        use Drupal\Core\Hook\Attribute\Hook;
        use Drupal\Core\Session\AccountInterface;
        use Drupal\Core\StringTranslation\StringTranslationTrait;
        use Drupal\user\UserDataInterface;
        ......@@ -29,7 +29,7 @@ public function __construct(
        *
        * @see \Drupal\user\ProfileForm::form()
        */
        #[FormAlter('user_form')]
        #[Hook('form_user_form_alter')]
        public function formUserFormAlter(&$form, FormStateInterface $form_state) : void {
        $form['contact'] = [
        '#type' => 'details',
        ......@@ -55,7 +55,7 @@ public function formUserFormAlter(&$form, FormStateInterface $form_state) : void
        *
        * Adds the default personal contact setting on the user settings page.
        */
        #[FormAlter('user_admin_settings')]
        #[Hook('form_user_admin_settings_alter')]
        public function formUserAdminSettingsAlter(&$form, FormStateInterface $form_state) : void {
        $form['contact'] = [
        '#type' => 'details',
        ......
        ......@@ -2,7 +2,7 @@
        namespace Drupal\contextual\Hook;
        use Drupal\Core\Hook\Attribute\Preprocess;
        use Drupal\Core\Hook\Attribute\Hook;
        use Drupal\Core\Session\AccountInterface;
        /**
        ......@@ -21,7 +21,7 @@ public function __construct(
        * @see contextual_page_attachments()
        * @see \Drupal\contextual\ContextualController::render()
        */
        #[Preprocess]
        #[Hook('preprocess')]
        public function preprocess(&$variables, $hook, $info): void {
        // Determine the primary theme function argument.
        if (!empty($info['variables'])) {
        ......
        ......@@ -2,7 +2,7 @@
        namespace Drupal\locale\Hook;
        use Drupal\Core\Hook\Attribute\Preprocess;
        use Drupal\Core\Hook\Attribute\Hook;
        use Drupal\Core\Language\LanguageInterface;
        use Drupal\Core\Language\LanguageManagerInterface;
        ......@@ -18,7 +18,7 @@ public function __construct(
        /**
        * Implements hook_preprocess_HOOK() for node templates.
        */
        #[Preprocess('node')]
        #[Hook('preprocess_node')]
        public function preprocessNode(&$variables): void {
        /** @var \Drupal\node\NodeInterface $node */
        $node = $variables['node'];
        ......
        ......@@ -4,7 +4,7 @@
        namespace Drupal\node\Hook;
        use Drupal\Core\Hook\Attribute\Preprocess;
        use Drupal\Core\Hook\Attribute\Hook;
        /**
        * Hook implementations for the node module.
        ......@@ -14,7 +14,7 @@ class NodeThemeHooks {
        /**
        * Implements hook_preprocess_HOOK() for node field templates.
        */
        #[Preprocess('field__node')]
        #[Hook('preprocess_field__node')]
        public function preprocessFieldNode(&$variables): void {
        // Set a variable 'is_inline' in cases where inline markup is required,
        // without any block elements such as <div>.
        ......
        ......@@ -4,19 +4,19 @@
        namespace Drupal\module_test_oop_preprocess\Hook;
        use Drupal\Core\Hook\Attribute\Preprocess;
        use Drupal\Core\Hook\Attribute\Hook;
        /**
        * Hook implementations for module_test_oop_preprocess.
        */
        class ModuleTestOopPreprocessThemeHooks {
        #[Preprocess]
        #[Hook('preprocess')]
        public function rootPreprocess($arg): mixed {
        return $arg;
        }
        #[Preprocess('test')]
        #[Hook('preprocess_test')]
        public function preprocessTest($arg): mixed {
        return $arg;
        }
        ......
        ......@@ -4,7 +4,7 @@
        namespace Drupal\theme_test\Hook;
        use Drupal\Core\Hook\Attribute\Preprocess;
        use Drupal\Core\Hook\Attribute\Hook;
        /**
        * Hook implementations for theme_test.
        ......@@ -14,7 +14,7 @@ class ThemeTestThemeHooks {
        /**
        * Implements hook_preprocess_HOOK().
        */
        #[Preprocess('theme_test_preprocess_suggestions__monkey')]
        #[Hook('preprocess_theme_test_preprocess_suggestions__monkey')]
        public function preprocessTestSuggestions(&$variables): void {
        $variables['foo'] = 'Monkey';
        }
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment