Provide a way to alter the block plugin configuration form

Created on 13 July 2018, over 6 years ago
Updated 19 May 2024, 7 months ago

When a block is selected in a block field, the block_field module loads the plugin for the block and then displays its configuration form inline via AJAX. Because this bypasses the normal block_form, form alter hooks have no effect.

It would be nice to be able to add fields to this form and use the ThirdPartySettings to store block placement attributes like colors or styling preferences.

This might be a way to integrate with the block_class module as well.

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cameron prince

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

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

    Totally agree this would still make sense to make this alterable. Or are there any other ways to hook into this form cleanly?

  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    This is really needed in cases where users select from menu_blocks as options only. Instead, they get two sets of blocks defined by both the system and menu_block modules, where I only want menu_block (because this presents the extra features of that module).

  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    To get around this in my case, I extended the field widget until there is another solution.

    
    /**
     * Plugin implementation of the 'block_field' widget.
     *
     * @FieldWidget(
     *   id = "mymodule_block_field",
     *   label = @Translation("Block field (for menus)"),
     *   field_types = {
     *     "block_field"
     *   }
     * )
     */
    class BlockFieldWidget extends BaseBlockFieldWidget {
    
      /**
       * {@inheritdoc}
       */
      public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
        $element = parent::formElement($items, $delta, $element, $form, $form_state);
    
        if (!empty($element["plugin_id"]["#options"]["Menus"])) {
          $options = $element["plugin_id"]["#options"]["Menus"];
          $element["plugin_id"]["#options"]["Menus"] = array_filter($options, fn ($option) => !str_contains($option, 'system_'), ARRAY_FILTER_USE_KEY);
        }
    
        return $element;
      }
    
    }
    
  • πŸ‡ΊπŸ‡¦Ukraine vlad.dancer Kyiv

    vlad.dancer β†’ made their first commit to this issue’s fork.

  • Status changed to Needs review 7 months ago
  • πŸ‡ΊπŸ‡¦Ukraine vlad.dancer Kyiv
Production build 0.71.5 2024