Missing hook to alter ChooseComponentController::list or ::componentMenu

Created on 24 March 2023, over 1 year ago
Updated 15 May 2024, about 1 month ago

Problem/Motivation

TL;DR:
There doesn't seem to be a hook for the layout paragraphs component list? (Paragraph type selection)

layout_paragraphs.api.php defines the following:

/**
 * Alter the Layout Paragraph component form.
 *
 * Implements hook_form_FORM_ID_alter().
 *
 * @param array $form
 *   The Layout Paragraph component form.
 * @param \Drupal\Core\Form\FormStateInterface $form_state
 *   The Layout Paragraph Component Form State.
 *
 * @see layout_paragraphs_form_layout_paragraphs_component_form_alter()
 * */
function hook_form_layout_paragraphs_component_form_alter(array &$form, FormStateInterface &$form_state) {
  // Make custom alterations to adjust the Layout Paragraph Component Form..
}

but neither the hook nor the hook in layout_paragraphs.module:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function layout_paragraphs_form_layout_paragraphs_component_form_alter(&$form, FormStateInterface $form_state) {
  $display = $form['#display'];
  if ($layout_paragraphs_fields = $display->getComponent('layout_paragraphs_fields')) {
    $form['layout_paragraphs']['#weight'] = $layout_paragraphs_fields['weight'];
  }
}

Is called when the paragraph field was empty before.

Steps to reproduce

  1. Create a node with a layout_paragraphs field and configure it to work
  2. In the node/x/edit form, click "Add section" and debug the calls. None of the two hooks above is called, when the "Choose a component" form modal is opened.

Proposed resolution

a) Ensure the hook is called for the selection / creation of components
or
b) Improve the documentation to point out that the hook is not intended to be called for "Choose a component" form

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

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

Comments & Activities

Production build 0.69.0 2024