Handle multiple values

Created on 9 January 2024, 10 months ago
Updated 22 April 2024, 7 months ago

Problem/Motivation

Currently the code does not handle multiple values.

For example in a contextual filter that is exposed you can enter multiple values (for example taxonomy IDS) with "+" or "," depending if you wantd AND or OR.

Currently the code assumes that "value" is a single ID and loads it. This should be changed and resolved.

Steps to reproduce

Have a contextual filter with multiple values and try to save a layout builder block for example with those exposed contextual filters with more than 1 value, for example "123+456".

Proposed resolution

Handle multiple values

Remaining tasks

Review & fix.

🐛 Bug report
Status

Needs review

Version

1.2

Component

Code

Created by

🇧🇪Belgium Mschudders

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

Comments & Activities

  • Issue created by @Mschudders
  • 🇧🇪Belgium Mschudders

    Before:

     if ($value) {
                $storage = \Drupal::entityTypeManager()->getStorage($entity_type);
                $entity = $storage->load($value);
                $form['override'][$block->getDerivativeId()][$type][$id]['value']['#default_value'] = $entity;
              }

    After:

     if ($value) {
                $storage = \Drupal::entityTypeManager()->getStorage($entity_type);
    
                $values = preg_split("/[\+,]+/", $value) ?: [];
                $default = $storage->loadMultiple($values);
                $form['override'][$block->getDerivativeId()][$type][$id]['value']['#default_value'] = $default;
              }
  • 🇧🇪Belgium Mschudders

    todo have to test mixing "+" and ",".

    Right now tested "+" and "single values"

  • 🇧🇪Belgium Mschudders

    fix pushed.

    Ongoing testing.

  • 🇧🇪Belgium arwillame

    I had some issues testing your proposition.
    The form configuration do not allowed me to have multiple values in the "entity_autocomplete".

    So i created a patch that allow the user to add multiple entities using the "#tags" parameter.
    I also add a check to only do that when the related view allow ultiple elements.

    Finally i made a little change in the execute method to be able to use the multiple values in the context filter itself.

    Please feel free to comment my proposition.

Production build 0.71.5 2024