Add static hook methods (and call them statically)

Created on 19 December 2023, 12 months ago

Problem/Motivation

When playing with this on an existing code base, i would often have needed this.

Typically when altering a plugin, but any class that does NOT get instantiated by the container, will do:

final class MyCustomEntityPrintClass extends PhpWkhtmlToPdf {

  /**
   * We can NOT put this hook into its class currently, as the container can not (and should not) create an instance.
   */
  #[Alter('entity_print_print_engine')]
  public static function alterEntityPrintPrintEngine(&$info) {
    $info['phpwkhtmltopdf']['class'] = self::class;
  }

  /**
   * Constructor called by plugin manager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ExportTypeInterface $export_type) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $export_type);
    // My custom code.
  }

}

Proposed resolution

Allow static hooks, and call them statically.

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany geek-merlin Freiburg, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024