Provide single field values from multivalue fields as layout builder-friendly blocks

Created on 31 January 2019, almost 6 years ago
Updated 28 December 2022, about 2 years ago

Problem/Motivation

For every multivalue field block, allow specifying which field delta(s) would be placed.

This would allow the edit form when initially creating the node to act as a kind of "copy deck" where an editor could input all of the text and images they knew they would need for their page/layout.

Proposed resolution

Add configuration to the field block itself.

When placing a multi-value field, select from:
- Display all items
- Display a specified number of items

If display all items is selected, no further settings are required.

If display a specified number of items is selected, show fields just like this how views handles it:

And a user could place that same multi-value image field as many times as they want, as is already the case.

Remaining tasks

User interface changes

Option 1: 2 types of field blocks

Create two versions of each field block.
A) "Fieldname: Display all items" (this is the one we have now)
B) "Fieldname: Specify number of items"

When A is selected, it uses the standard placement behavior.
When B is selected, the user sees a form like there is in the views module:

Option 2: 1 type of field block, w/ more configuration

Upon placing a field block for a multi-value field, display radio buttons in the sidebar:
- Display all items
- Display a specified number of items

If "Display all items" is selected, you are done. If "Display a specified number of items" is selected, then load additional fields (offset & # of items, as pictured above).

API changes

Either approach can easily be fully backwards-compatible. Previously placed multivalue fields are the same as fields with "Display all items" selected.

Data model changes

Release notes snippet

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
Layout builderΒ  β†’

Last updated 3 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States ashrafabed

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

  • last update over 1 year ago
    Custom Commands Failed
  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    Here a version of the patch that works on 10.1

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    30,516 pass, 2 fail
  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    rhovland β†’ changed the visibility of the branch 11.x to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    rhovland β†’ changed the visibility of the branch 10.1.x to hidden.

  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    rhovland β†’ changed the visibility of the branch 3029830-field-block-offsets to hidden.

  • Pipeline finished with Failed
    5 months ago
    Total: 262s
    #255298
  • Pipeline finished with Failed
    5 months ago
    Total: 563s
    #255309
  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    The old branch was empty so I made a new one based on 11.x

    There's one test failure but it doesn't seem like it's related to these changes?

  • Pipeline finished with Failed
    5 months ago
    Total: 522s
    #255319
  • πŸ‡³πŸ‡ΏNew Zealand danielveza Brisbane, AU

    I haven't done a comprehensive review of this yet since it's not green, but does the test need to be FunctionalJS? I think we can just do a Functional test here

  • πŸ‡ͺπŸ‡ΈSpain javier_rey

    I think that the patch #44 has a bug. If you set a field with β€œNumber of items to display = 0”, when you reach to the second "if”, the condition will be FALSE and will not hide unwanted fields.

    if ($items_to_display = (int) $block_configuration['items_to_display']) {

          // If this is a multi-value block configured to not display all values,
          // remove those field items from the render array.
          $block_configuration = $block->getConfiguration();
          if (!$is_content_empty && isset($block_configuration['display_items']) && $block_configuration['display_items'] == 'display_some') {
            if ($items_to_display = (int) $block_configuration['items_to_display']) {
              $offset = (int) $block_configuration['offset'];
              $range = range(0, $content[0]['#items']->count());
              foreach ($range as $key) {
                $top_range = $offset + $items_to_display - 1;
                if ($key < $offset || $key > $top_range) {
                  $content[0][$key]['#access'] = FALSE;
                }
              }
            }
          }
  • πŸ‡ΊπŸ‡ΈUnited States MegaKeegMan

    I can confirm that bug. Also I wanted to mention that this particular solution will be a bit difficult to use, especially in the case that there are a lot of deltas in field. I wonder if it makes sense to also display the index of each delta in the preview to make it easier to select the values you are looking for

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

    I went ahead and made a small change to patch #44 (I made against 10.3.x), which addresses both the bug and my need for an index to be displayed. I am happy to take any feedback, and if people like I can update the issue fork too. I pretty much just touched the code mentioned in #51.

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

    Potential improvements to make on #53:

    • make indices always display, even when offset and items to display are both 0
    • Add block configuration to control whether the indices should be shown in the preview
  • πŸ‡ΊπŸ‡ΈUnited States MegaKeegMan

    Sorry #53 was still buggy, so ignore that one. This new one is what I meant for #53 to be. I did not make any improvements mentioned in #54. Again, this patch is for 10.3.x, but if the changes are agreeable, happy to commit them into the fork.

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

    Oops I didn't realize that the changes I made affected things outside of preview mode. One more fix to make sure my index strings only show up in preview mode.

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

    Okay one thing I really don't like about this implementation is that when you change the order of the deltas in the edit form, including when you delete a value, the items that you have displayed in the layout change.

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

    But I acknowledge that this might be a feature for some people.

  • πŸ‡ΊπŸ‡ΈUnited States MegaKeegMan
  • Pipeline finished with Failed
    3 months ago
    Total: 557s
    #323311
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Left comments on MR.

  • I ran testBlockAccess locally and it passed. The CI says that it failed:

    https://git.drupalcode.org/issue/drupal-3029830/-/jobs/3186760

  • Pipeline finished with Canceled
    3 months ago
    Total: 31s
    #323443
  • Pipeline finished with Canceled
    3 months ago
    Total: 132s
    #323440
  • Pipeline finished with Failed
    3 months ago
    Total: 545s
    #323444
Production build 0.71.5 2024