Provide a Config Action to add/edit a component in a layout

Created on 18 September 2024, 3 months ago

Problem/Motivation

There is currently no way to add or alter items in a layout. We should have a config action that allows recipe to add or edit items in a layout.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

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

Merge Requests

Comments & Activities

  • Issue created by @thejimbirch
  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • First commit to issue fork.
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    Thought that this could fit in SectionListTrait, but timplunkett pointed out that this would only make sense in config based section lists, so will be its own trait.

  • Pipeline finished with Failed
    2 months ago
    Total: 110s
    #306122
  • Pipeline finished with Success
    2 months ago
    Total: 546s
    #306319
  • πŸ‡ͺπŸ‡ΈSpain plopesc Valladolid

    Great step forward @penyaskito. Really looking forward to have this in core!

    Tried to test it locally to integrate it with navigation module with no luck. Probably I missed one or more steps.

    Steps I followed:

    • Clone the branch
    • Add use ConfigSectionListTrait; to NavigationSectionListStorage
    • Implement uuidGenerator() method
    • Clear cache at least once
    • Execute ddev . php core/scripts/drupal recipe modules/my_recipe
    • Get the error: The "addComponent" plugin does not exist. Valid plugin IDs for Drupal\Core\Config\Action\ConfigActionManager are: ....

    Create a recipe.yml like this:

    name: Navigation Test Recipe
    type: Examples
    description: 'Adds a block to navigation.'
    install:
      - navigation
    config:
      actions:
        navigation.block_layout:
          addComponent:
            section: 0
            position: 1
            value:
              uuid: 30000000-0000-1000-a000-000000000000
              id: 'navigation_menu:content'
              label: Content From Recipe
              label_display: 1
              provider: navigation
              region:
                content: 'content'
              default_region: content
              level: 1
              depth: 2

    Could you please indicate the steps I missed?

    Thank you!

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    Apparently I was wrong and looking at \Drupal\Core\Config\Action\Plugin\ConfigAction\Deriver\EntityMethodDeriver::getDerivativeDefinitions, ActionMethods are only valid for ConfigEntityTypeInterface implementations, so Navigation will need to declare its own ConfigAction plugin.

    So this will only be useful as is for LayoutBuilderEntityViewDisplay in core, and of course contrib.

  • Pipeline finished with Failed
    2 months ago
    Total: 558s
    #312398
  • Pipeline finished with Failed
    2 months ago
    Total: 724s
    #312405
  • Pipeline finished with Failed
    2 months ago
    Total: 187s
    #312433
  • Pipeline finished with Failed
    2 months ago
    Total: 139s
    #312435
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    MR is ready for review. We might want more test coverage for the weight recalculation, but I'd prefer to get feedback on the direction.
    I'm not sure how are we testing config actions. Ideally we would have test recipes instead of just testing the method.

    We might want to implement this in LayoutBuilderEntityViewDisplay, but not sure if part of the same MR.

  • Pipeline finished with Canceled
    2 months ago
    Total: 166s
    #312464
  • Pipeline finished with Canceled
    2 months ago
    Total: 173s
    #312466
  • Pipeline finished with Canceled
    2 months ago
    Total: 78s
    #312472
  • Pipeline finished with Failed
    2 months ago
    Total: 230s
    #312473
  • Pipeline finished with Failed
    2 months ago
    Total: 511s
    #312481
  • Pipeline finished with Failed
    2 months ago
    Total: 385s
    #312494
  • Pipeline finished with Canceled
    2 months ago
    Total: 230s
    #312512
  • Pipeline finished with Failed
    2 months ago
    Total: 398s
    #312515
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Drupal CMS is going to need this, tagging accordingly.

  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Kicking back for addressing my remaining feedback. :) But I think this is a great start on a helpful action, and I'd really like to see it in core.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    Didn't remove the changed I had before yet.

    This means that setSection needs to change its visibility from protected to public in SectionListTrait.

    Not sure if I implemented the deriver right, but this worked for me with a slightly different version of the previous recipe:

    config:
      actions:
        dashboard.dashboard.test:
          addComponent:
            section: 0
            position: 4
            component:
              uuid: 01929a0b-056f-72c1-b390-c9bdc3f6fd5e
              id: dashboard_text_block
              label: 'My new dashboard with weight from a plugin'
              label_display: 'visible'
              provider: 'dashboard'
              region:
                layout_twocol_section: 'second'
              default_region: content
              context_mapping: { }
              text:
                value: '<p>My new dashboard with weight from plugin</p>'
                format: 'basic_html'
    
    
  • Pipeline finished with Failed
    2 months ago
    Total: 185s
    #313107
  • Pipeline finished with Failed
    about 1 month ago
    Total: 159s
    #337828
  • Pipeline finished with Failed
    about 1 month ago
    Total: 242s
    #337841
  • Pipeline finished with Failed
    about 1 month ago
    Total: 233s
    #337879
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    This needs better test coverage.

    We only cover adding new components. I'd expect we want a separate action for adding multiple components, and a separate one of editing existing components, as @phenaproxima said it would be better to have them separated.
    Not sure if we should cover these here or in follow-ups.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 213s
    #337896
  • Pipeline finished with Failed
    about 1 month ago
    Total: 148s
    #337903
  • πŸ‡­πŸ‡ΊHungary GΓ‘bor Hojtsy Hungary

    The MR only seems to add the "add layout component" action, so I think its far that it only has tests for that. @phenaproxima indicated that these improvements to the tests would be good, that still looks like needs work:

    • We need to be sure the region stuff works as expected, including when the default region is used, or the region can't be resolved.
    • We need to be sure the position stuff is figured out correctly, every way it could be passed in.
    • We need to be sure that the additonal key is preserved if passed.
    • The test...isn't using config actions. That obviates the entire point of this MR. We need to test that we can accomplish the addition of the component using config actions. (We don't need to use a recipe, but we probably need ConfigActionManager::applyAction(...).
  • Status changed to Needs work about 1 month ago
  • πŸ‡­πŸ‡ΊHungary GΓ‘bor Hojtsy Hungary

    Reached out to phpstan folks. Learned that πŸ› Add missing @return types for StringTranslationTrait::formatPlural() and ::getNumberOfPlurals() Active is in the way, until that lands, the phpstan baseline needs updating in the MR.

  • Pipeline finished with Success
    about 1 month ago
    Total: 2191s
    #343070
  • Pipeline finished with Success
    about 1 month ago
    Total: 580s
    #343117
  • πŸ‡¦πŸ‡ΊAustralia pameeela
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Discussed with @penyaskito and we agreed that this is nice to have, and would accelerate Drupal CMS's dashboard work track, but is not a stable blocker.

  • πŸ‡¦πŸ‡ΊAustralia pameeela

    Tagging as a target so it's on the radar somewhere, it's intended to be used for nice-to-haves.

Production build 0.71.5 2024