Handle multiple values

Created on 9 January 2024, 6 months ago
Updated 22 April 2024, 2 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.69.0 2024