No matter what I do, I can't swap the class of the SDC plugin

Created on 18 October 2023, about 1 year ago
Updated 7 August 2024, 3 months ago

Problem/Motivation

In a 3rd-party I want to swap the SDC plugin class, which currently is src/Plugin/Component.

  • As we use to do that in Drupal, I first looked for something like `hook_SOMETHING_info_alter()`. But the SDC plugin manager says:
    // Note that we are intentionally skipping $this->alterInfo('sdc_info');
    // We want to ensure that everything related to a component is in the
    // single directory. If the alteration of a component is necessary,
    // component replacement is the preferred tool for that.
    

    and doesn't provide such a hook

  • No problem, I said. I will swap the plugin manager class, using a *ServiceProvider magic class, and I will add my own class in `DefaultPluginManager::$defaults`.
  • No way, the `ComponentPluginManager` plugin manager class is final.
  • Then I went with decorating. I've intercepted the definition in MyPluginManagerClass::processDefinition() and changed the class. It works.
  • But now it crashes in `\Drupal\sdc\Twig\TwigComponentLoader::__construct()` because the plugin manager, passed as 1st argument, is strict-typed to `\Drupal\sdc\ComponentPluginManager`, so I can't pass the custom class that swapped SDC plugin manager.

Trying to extend SDC in any direction seems quite impossible, not only when to comes to my scope. The whole module seems so hermetic.

This is also helpful for cl_editorial as would help to switch from form alters to plugin forms:

  • Swap the Component plugin class with one that extend Component but also implements PluginFormInterface
  • Implement PluginFormInterface::buildConfigurationForm() and inside, use ComponentInputToForm to build/return the form
  • Then, with a SDC plugin instance say $component_plugin, you can easily get the component form: $component_plugin->buildConfigurationForm() instead of form alters

Steps to reproduce

See "Problem/Motivation"

Proposed resolution

  • Allow to alter plugin definitions, as we allow in any Drupal plugin type.
  • Remove "final" from plugin & plugin manager classes.
  • Create a `ComponentInterface` so that we can properly strict-typing parameters, class properties and variables.
  • Revisit strict-typing of parameters and and sure they're using the interface, not specific class

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Postponed

Version

11.0 πŸ”₯

Component
single-directory componentsΒ  β†’

Last updated about 19 hours ago

Created by

πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024