Does not work with Drupal Profile fields

Created on 19 November 2024, 29 days ago

The module does not work when using Layout Builder with Drupal Profile module fields or Drupal user fields. Unless I'm missing something. Would be nice to work across all entities.

Feature request
Status

Active

Version

2.2

Component

Code

Created by

🇬🇧United Kingdom tonyhrx

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

Comments & Activities

  • Issue created by @tonyhrx
  • 🇬🇧United Kingdom tonyhrx

    Actually it does work but it looks like I have a few theme issues going on. Apols

  • 🇬🇧United Kingdom tonyhrx

    OK I double check and it does not work. Here' s a fix for ManageComponentAttributesForm.php

    <?php
    
    namespace Drupal\layout_builder_component_attributes\Form;
    
    use CssLint\Linter;
    use Drupal\Component\Utility\Html;
    use Drupal\Core\Ajax\AjaxFormHelperTrait;
    use Drupal\Core\Config\ConfigFactory;
    use Drupal\Core\Form\FormBase;
    use Drupal\Core\Form\FormInterface;
    use Drupal\Core\Form\FormStateInterface;
    use Drupal\layout_builder\Controller\LayoutRebuildTrait;
    use Drupal\layout_builder\LayoutBuilderHighlightTrait;
    use Drupal\layout_builder\SectionStorageInterface;
    use Drupal\layout_builder\LayoutTempstoreRepositoryInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    
    class ManageComponentAttributesForm extends FormBase implements FormInterface {
      use AjaxFormHelperTrait;
      use LayoutBuilderHighlightTrait;
      use LayoutRebuildTrait;
    
      protected $sectionStorage;
      protected $delta;
      protected $uuid;
      protected $layoutTempstore;
      protected $configFactory;
    
      public function __construct(LayoutTempstoreRepositoryInterface $layout_tempstore_repository, ConfigFactory $config_factory) {
        $this->layoutTempstore = $layout_tempstore_repository;
        $this->configFactory = $config_factory;
      }
    
      public static function create(ContainerInterface $container) {
        return new static(
          $container->get('layout_builder.tempstore_repository'),
          $container->get('config.factory')
        );
      }
    
      public function getFormId() {
        return 'layout_builder_manage_attributes_form';
      }
    
      public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $uuid = NULL) {
        if (!$section_storage || $delta === NULL || !$uuid) {
          throw new \InvalidArgumentException('ManageComponentAttributesForm requires all parameters.');
        }
    
        $this->sectionStorage = $section_storage;
        $this->delta = $delta;
        $this->uuid = $uuid;
    
        $config = $this->configFactory->get('layout_builder_component_attributes.settings')->get();
        $section = $section_storage->getSection($delta);
        $component = $section->getComponent($uuid);
        $component_attributes = $component->get('component_attributes') ?? [];
    
        $form['#attributes']['data-layout-builder-target-highlight-id'] = $this->blockUpdateHighlightId($uuid);
    
        $attribute_categories = [
          'block_attributes' => $this->t('Block attributes'),
          'block_title_attributes' => $this->t('Block title attributes'),
          'block_content_attributes' => $this->t('Block content attributes'),
        ];
    
        foreach ($attribute_categories as $category => $title) {
          if ($this->hasAllowedAttributes($config["allowed_$category"])) {
            $form[$category] = $this->buildAttributeFieldset($title, $config["allowed_$category"], $component_attributes[$category] ?? []);
          }
        }
    
        $form['actions']['submit'] = [
          '#type' => 'submit',
          '#value' => $this->t('Update'),
          '#button_type' => 'primary',
          '#ajax' => $this->isAjax() ? ['callback' => '::ajaxSubmit'] : [],
        ];
    
        $form['#tree'] = TRUE;
        return $form;
      }
    
      // Rest of the existing methods remain the same...
    }

    Here's a fix for layout_builder_component_attributes.routing.yml

    layout_builder_component_attributes.settings:
      path: '/admin/config/content/layout-builder-component-attributes'
      defaults:
        _form: '\Drupal\layout_builder_component_attributes\Form\GlobalSettingsForm'
        _title: 'Layout Builder Component Attributes Settings'
      requirements:
        _permission: 'administer layout builder component attributes'
    
    layout_builder_component_attributes.manage_attributes:
      path: '/layout_builder/update/block-attributes/{section_storage_type}/{section_storage}/{delta}/{uuid}'
      defaults:
        _form: '\Drupal\layout_builder_component_attributes\Form\ManageComponentAttributesForm'
        _title: 'Manage attributes'
      requirements:
        _permission: 'manage layout builder component attributes'
        _layout_builder_access: 'view'
      options:
        _admin_route: TRUE
        parameters:
          section_storage:
            layout_builder_tempstore: TRUE

    Should now work with any fieldable entity.

Production build 0.71.5 2024