Commit 851dad06 authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch
Browse files

Issue #3313728 by e0ipso: Use the new service in CL Editorial

parent c7ad8344
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
 */

use Drupal\cl_components\Plugin\Component;
use Drupal\cl_editorial\NoThemeComponentManager;

/**
 * Implements hook_cl_component_audit_alter().
@@ -15,10 +16,11 @@ function cl_block_cl_component_audit_alter(array &$card_build, Component $compon
  $allowed_components = &drupal_static(__FUNCTION__);
  if (!isset($allowed_components)) {
    $settings = \Drupal::config('cl_block.settings');
    $discovery = cl_components_manager();
    $component_manager = \Drupal::service(NoThemeComponentManager::class);
    assert($component_manager instanceof NoThemeComponentManager);
    $allowed_components = array_map(
      static fn(Component $c) => $c->getId(),
      $discovery->getAllComponentsWithoutDupesWithFilters(
      $component_manager->getFilteredComponentTypes(
        $settings->get('allowed'),
        $settings->get('forbidden'),
        $settings->get('types'),
+8 −7
Original line number Diff line number Diff line
@@ -2,9 +2,9 @@

namespace Drupal\cl_block\Form;

use Drupal\cl_components\ComponentPluginManager;
use Drupal\cl_components\Exception\ComponentNotFoundException;
use Drupal\cl_components\Exception\InvalidComponentHookException;
use Drupal\cl_editorial\NoThemeComponentManager;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\CloseModalDialogCommand;
@@ -25,17 +25,18 @@ class ClBlockDialog extends FormBase {
  /**
   * Constructs a ElementEmbedDialog object.
   *
   * @param \Drupal\cl_components\ComponentPluginManager $pluginManager
   *   The plugin manager.
   * @param \Drupal\cl_editorial\NoThemeComponentManager $componentManager
   *   The component manager.
   */
  public function __construct(protected ComponentPluginManager $pluginManager) {}
  public function __construct(protected NoThemeComponentManager $componentManager) {
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('plugin.manager.cl_component')
      $container->get(NoThemeComponentManager::class)
    );
  }

@@ -108,7 +109,7 @@ class ClBlockDialog extends FormBase {
      ],
    ];
    try {
      $component = $this->pluginManager->findWithoutThemeFilter($cl_component['data-component-id'] ?? '');
      $component = $this->componentManager->findWithoutThemeFilter($cl_component['data-component-id'] ?? '');
    }
    catch (ComponentNotFoundException $e) {
      return $form;
@@ -272,7 +273,7 @@ class ClBlockDialog extends FormBase {
        'data-component-id',
        'machine_name',
      ]);
      $component = $this->pluginManager->findWithoutThemeFilter($machine_name);
      $component = $this->componentManager->findWithoutThemeFilter($machine_name);
    }
    catch (ComponentNotFoundException $e) {
      watchdog_exception('cl_block', $e);
+6 −6
Original line number Diff line number Diff line
@@ -2,10 +2,10 @@

namespace Drupal\cl_block\Form;

use Drupal\cl_components\Plugin\Component;
use Drupal\cl_components\ComponentPluginManager;
use Drupal\cl_components\Exception\ComponentNotFoundException;
use Drupal\cl_components\Exception\InvalidComponentHookException;
use Drupal\cl_components\Plugin\Component;
use Drupal\cl_editorial\NoThemeComponentManager;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
@@ -35,13 +35,13 @@ class ClComponentForm {
   *   The component name.
   * @param \Shaper\Transformation\TransformationInterface $formGenerator
   *   The form generator.
   * @param \Drupal\cl_components\ComponentPluginManager $pluginManager
   *   The component plugin manager.
   * @param \Drupal\cl_editorial\NoThemeComponentManager $componentManager
   *   The component manager.
   */
  public function __construct(
    protected readonly string $componentName,
    protected readonly TransformationInterface $formGenerator,
    protected readonly ComponentPluginManager $pluginManager
    protected readonly NoThemeComponentManager $componentManager
  ) {
  }

@@ -178,7 +178,7 @@ class ClComponentForm {
   */
  protected function getComponent(): Component {
    if (empty($this->component)) {
      $this->component = $this->pluginManager->findWithoutThemeFilter($this->componentName);
      $this->component = $this->componentManager->findWithoutThemeFilter($this->componentName);
    }
    return $this->component;
  }
+10 −7
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@

namespace Drupal\cl_block\Form;

use Drupal\cl_components\ComponentPluginManager;
use Drupal\cl_editorial\Form\ComponentFiltersFormTrait;
use Drupal\cl_editorial\NoThemeComponentManager;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
@@ -20,17 +20,20 @@ class SettingsForm extends ConfigFormBase {
  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactoryInterface $config_factory, private readonly ComponentPluginManager $pluginManager, private readonly BlockManagerInterface $blockManager) {
  }
  public function __construct(
    ConfigFactoryInterface $config_factory,
    private readonly NoThemeComponentManager $componentManager,
    private readonly BlockManagerInterface $blockManager
  ) {}

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $plugin_manager = $container->get('plugin.manager.cl_component');
    $component_manager = $container->get(NoThemeComponentManager::class);
    return new static(
      $container->get('config.factory'),
      $plugin_manager,
      $component_manager,
      $container->get('plugin.manager.block')
    );
  }
@@ -56,9 +59,9 @@ class SettingsForm extends ConfigFormBase {
    $settings = $this->config('cl_block.settings')->get();
    // I am unsure why we need this, but the component discovery is not
    // initialized in ajax callbacks sometimes.
    $plugin_manager = isset($this->pluginManager) ? $this->pluginManager : cl_components_manager();
    $component_manager = $this->componentManager ?? \Drupal::service(NoThemeComponentManager::class);
    $message = $this->t('Set a combination of filters to control the list of components that will become blocks.');
    static::buildSettingsForm($form, $form_state, $plugin_manager, $settings, [], $message);
    static::buildSettingsForm($form, $form_state, $component_manager, $settings, [], $message);
    return parent::buildForm($form, $form_state);
  }

+6 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\cl_block\Plugin\Block;
use Drupal\cl_block\Form\ClComponentForm;
use Drupal\cl_block\Render\ComponentBlockRenderer;
use Drupal\cl_components\Plugin\Component;
use Drupal\cl_editorial\NoThemeComponentManager;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
@@ -120,7 +121,11 @@ class ComponentBlock extends BlockBase implements ContainerFactoryPluginInterfac
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    // Get the entity type and field name from the plugin ID.
    [, $component_name] = explode(static::DERIVATIVE_SEPARATOR, $plugin_id, 4);
    $form_helper = new ClComponentForm($component_name, $container->get('cl_block.form_generator'), $container->get('plugin.manager.cl_component'));
    $form_helper = new ClComponentForm(
      $component_name,
      $container->get('cl_block.form_generator'),
      $container->get(NoThemeComponentManager::class)
    );
    return new static(
      $configuration,
      $plugin_id,
Loading