claro_form_views_ui_config_item_form_alter() assumes a suffix when there is a prefix leading to: Undefined index #suffix in $form['options']['value']

Created on 30 November 2021, over 2 years ago
Updated 23 April 2024, about 2 months ago

Problem/Motivation

There are certain contrib modules which further extends the functionality of views by providing new features, for example new filters, etc. One such example is when using contrib module called select_translation. Now this module for provides a new custom filter but, when using this module with Claro theme in views UI we get an ajax error. This error comes from Claro.theme file from line 1547 which is unable to find
$form['options']['value']['#suffix']. The line of code is

line: 1546

$form['options']['operator']['#prefix'] = '<div class="views-config-group-region">' . str_replace($left_class, 'views-group-box--operator', $form['options']['operator']['#prefix']);

line: 1547

$form['options']['value']['#suffix'] = $form['options']['value']['#suffix'] . '</div>';

Due to this ajax error, the filter is cannot be edited/modified as the views_ui does not open the filter so that we could view its content.

There is also a @todo mentioned few lines above pointing to url https://drupal.org/node/3164890
todo is as follows

Many of the changes to classes within this conditional may not be needed or require refactoring in https://drupal.org/node/3164890

Since there is a todo already mentioned and the theme is constantly updating we need to provide some sort of condition which can avoid such issues.

Steps to reproduce

This can be reproduced by using
Drupal Core: 10.2.4
Admin Theme: Claro

Create a random node view of type article or basic page, add some fields, add some filter and then add filter "Select translation", you will not be able to modify the filter as it will give you an ajax error. You can check that in your console tab or networks tab in chrome by doing inspect element.

Proposed resolution

Output an empty suffix when is not present

🐛 Bug report
Status

Fixed

Version

10.2

Component
Claro 

Last updated 18 minutes ago

Created by

🇫🇮Finland Shabbir

Live updates comments and jobs are added and updated live.
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.

  • 🇺🇸United States KurtTrowbridge

    Hello! I had the same issue involving the same select_translation module, and the patch in #6 worked for me. Marking as RTBC. Thanks!

  • 🇪🇸Spain rodrigoaguilera Barcelona

    Claro is now in core but it suffers from the same

  • Status changed to Needs work 3 months ago
  • The Needs Review Queue Bot tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • Status changed to Needs review 3 months ago
  • 🇪🇸Spain rodrigoaguilera Barcelona

    I proposed a different approach that outputs the suffix as an empty string since the latest patch was not closing the div.

  • Pipeline finished with Canceled
    3 months ago
    Total: 452s
    #129019
  • Pipeline finished with Success
    3 months ago
    Total: 490s
    #129025
  • 🇺🇸United States smustgrave

    Hiding patches but wonder if this is a bug for select_translation.

  • 🇪🇸Spain rodrigoaguilera Barcelona

    This issue happened to me with facets 3.x and better exposed filters 6.0.3. I'm not sure which one caused it.
    I think is quite legitimate to define a prefix without a suffix

  • Status changed to RTBC 2 months ago
  • 🇺🇸United States smustgrave

    Not 100% sure on the scenario but do see the error.

    Per 🌱 [policy, no patch] Better scoping for bug fix test coverage RTBC I believe this may fall under that scenario where the fix is small enough we might not need a full test case for it.

  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    This needs more investigate as it points to something else that is broken. Look at the full scope of code here:

        // Remove `views-(direction)-(amount)` classes, replace with
        // `views-group-box--operator`, and add a `views-config-group-region`
        // wrapper.
        if (isset($form['options']['operator']['#prefix'])) {
          foreach (['views-left-30', 'views-left-40'] as $left_class) {
            if (str_contains($form['options']['operator']['#prefix'], $left_class)) {
              $form['options']['operator']['#prefix'] = '<div class="views-config-group-region">' . str_replace($left_class, 'views-group-box--operator', $form['options']['operator']['#prefix']);
              $form['options']['value']['#suffix'] = $form['options']['value']['#suffix'] . '</div>';
              $form['options']['value']['#suffix'] = ($form['options']['value']['#suffix'] ?? '') . '</div>';
            }
          }
        }
    

    How have we got to a situation where both if (isset($form['options']['operator']['#prefix'])) { and if (str_contains($form['options']['operator']['#prefix'], $left_class)) { are true but we have no prefix...

    AHHH... I see the prefix is in $form['options']['operator'] and the suffix is in $form['options']['value'] that's very interesting. I think what Claro is doing here is icky and fragile. I'm not sure what's best for Claro but I agree that fixing this for contrib feels right and not requiring a test is okay too.

  • Status changed to Fixed 2 months ago
  • 🇪🇸Spain ckrina Barcelona
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Discussed with @ckrina who pointed out that

    It’s the eternal Drupal problem of dealing with markup logic in several places, and using #suffix and #prefix for what they are not prepared for. Not sure if that could be done on a template. I’d merge the quick fix and work the source of the problem in a follow-up.

    @ckrina also pointed out the perhaps the follow-up is 📌 Remove floats and clearfixes Active

    Committed and pushed b4263a3e42 to 11.x and cbf32be712 to 10.3.x and cb6fb284cb to 10.2.x. Thanks!

    Backported to 10.2.x as a safe bugfix and didn't require tests as per @smustgrave in #17

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024