Doesn't work with boolean field as target: PluginNotFoundException: The "" plugin does not exist

Created on 3 July 2023, almost 2 years ago

Problem/Motivation

Can't add a field state of type Invisible (Hide) on a boolean target; either one of both these problems arise:

  1. I can't set the state using a boolean field as the target: when you select it nothing happens in the UI other than infinite loading animation and this error is thrown:
    Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" plugin does not exist. Valid plugin IDs for Drupal\field_states_ui\FieldStateManager are: unchecked, disabled, required, optional, enabled, visible, checked, invisible, expanded, collapsed in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /var/www/html/web/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php)
  2. After many tries and combination of clicks I could somehow set the boolean field as target, but every time I save, another empty field state is added automatically on top:

I was surprised nobody had reported this error in the issue queue so I guess it has arisen with the recent core minor update?

Steps to reproduce

Fresh Drupal 10.1 install, add a boolean field to Article content type, go to manage form display, edit the Tags (or any) field to try adding a Field state, select the boolean field, error 1 appears.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇮🇹Italy kopeboy Milan

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

Merge Requests

Comments & Activities

  • Issue created by @kopeboy
  • 🇮🇹Italy kopeboy Milan

    Actually in case 2, even if the field state appears to be defined in the UI, when you go to the entity add form and try to trigger it, it doesn't work and this warning in thrown:
    Warning: Trying to access array offset on value of type null in Drupal\field_states_ui\FieldStateBase->applyState() (line 75 of /var/www/html/web/modules/contrib/field_states_ui/src/FieldStateBase.php)

  • 🇺🇸United States TolstoyDotCom L.A.

    I looked into this a bit and I can do more on request.

    Click the gear icon on admin/structure/types/manage/article/form-display next to the Title field.
    In Manage Field States, choose 'Enable' and click 'Add'.

    At that point, this code from FieldStateManager::settingsForm will set $type to 'enabled':

            $type = $form_state->getValue([
              'fields',
              $field_name,
              'settings_edit_form',
              'third_party_settings',
              'field_states_ui',
              'form',
              'type',
            ]);

    That's because 'third_party_settings' in form_state is like this:

    Array
    (
        [field_states_ui] => Array
            (
                [form] => Array
                    (
                        [type] => enabled
                        [list] => [NULL]
                        [add] => Drupal\Core\StringTranslation\TranslatableMarkup
                    )
            )
    )

    Then, change 'Comparison Type' to 'filled' and it throws a (silent) exception because there's no 'type' key in the 'third_party_settings' array:

    Array
    (
        [field_states_ui] => Array
            (
                [form] => Array
                    (
                        [edit] => Array
                            (
                                [target] => uid
                                [comparison] => filled
                                [value] => [NULL]
                                [submit] => Array
                                    (
                                        [save] => Drupal\Core\StringTranslation\TranslatableMarkup
                                        [cancel] => Drupal\Core\StringTranslation\TranslatableMarkup
                                    )
                            )
                        [list] => [NULL]
                    )
            )
    )
    

    The missing 'type' key leads to "The "" plugin does not exist..."

  • 🇦🇺Australia pasan.gamage

    I've been running in to the same error but with "Visible" option.

  • I'm running into this problem as well for my project, but weirdly enough not on all environments. So I'm nopt sure it I'm experiencing a different error but I do have a boolean field used to toggle other fields.

    I get the following error in the log:
    TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in array_keys() (line 238 of /web/modules/contrib/field_states_ui/src/FieldStateManager.php)

    So it breaks in generating a notice

    if (!isset($target['#field_parents'])) {
      $parents = [];
      $this->logger->notice(
        t(
          '#field_parents key not found. This will may cause problems. If so, please report on the @link. For quickest resolution, please include the element details: @details',
          [
            '@link' => Link::fromTextAndUrl(
              t('Field States UI Issue Queue'),
              Url::fromUri('https://www.drupal.org/project/issues/field_states_ui')
            )->toString(),
            '@details' => var_export(array_keys($element[0]),TRUE),
          ]
        )
      )

    I mean, I can easily just patch that the var_export isn't used if $element[0] is NULL and yes then the field_state works as expected.
    But I'm guessing the real questions is why $element[0] is NULL in this context. I don't have an answer right now since I haven't debugged it (yet).

  • 🇺🇦Ukraine serhii shandaliuk

    Any workarounds how we can solve it? I have the same issue with the user's entity.

  • 🇮🇹Italy kopeboy Milan

    ended up using the conditional_fields module..

  • 🇺🇸United States Topplestack Rural, Idaho

    I'm getting this error message regardless at the moment. Whether on a simple text field, boolean, text list, number, etc.

  • 🇨🇿Czech Republic parisek

    I get same error with current Drupal 10.1.5. Adjusted priority to critical because module is unusable.

  • 🇺🇸United States alex.verhoeven

    Experiencing exactly the same issue. Only if I leave the Target and Comparison fields untouched and then save, does it add the state. I am not able to change either field, or edit an existing state. If I try to edit the existing state, I get:

    Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" plugin does not exist. Valid plugin IDs for Drupal\field_states_ui\FieldStateManager are: required, visible, collapsed, unchecked, invisible, optional, checked, enabled, expanded, disabled in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

  • 🇧🇩Bangladesh linkanp

    I am getting extactly the same issue as alex.verhoeven This issue needs to be resolved.

  • 🇺🇸United States sascher

    We are seeing this issue also. We have a new install of the module on Drupal v 10.2.0

  • 🇩🇪Germany zuernbernhard

    Once you choose something in the third-party-settings form for comparison (eg value) or target (other field) - an Ajax Call is made to rebuild the form and the form state with the new plugin type information for the third party settings is gone

  • 🇩🇪Germany hauke-vq Berlin, Germany

    Most simply solution for now is just to disable the javascript while configuring the states.
    But a patch for this is pretty wanted.

  • 🇧🇩Bangladesh linkanp

    I have bypassed this issue by creating config yaml files manually for the new Field States. If anyone want, I would share my code with them.

  • 🇨🇦Canada briskly

    @linkanp - care to share your approach? I've been scratching my head for days now.

  • 🇵🇹Portugal adaragao

    I'm using the Brave browser, so I just went to the "Shields" Option ( Lion head on address bar), and activated the option "Block Scripts". Then I as able to do the conditions. I'm sure that other browsers have similar options.

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    23 pass, 24 fail
  • Status changed to Needs review about 1 year ago
  • 🇬🇧United Kingdom jofitz

    I have simplified the issue title because it appears to affect more than just Boolean fields.

    I think 2 separate issues are being discussed here.

    1. I have created an MR to fix the The "" plugin does not exist bug.
    2. I have created a new issue, with an MR, ( 🐛 Unable to change either the Target or Comparison elements Needs review ) to address the bug with being unable to change either the Target or Comparison elements (first mentioned by @alex.verhoeven, #3371927-12: PluginNotFoundException: The "" plugin does not exist )
  • 🇮🇳India narendragupta

    I am also facing the same issue while adding the visible field state.
    Need patch fix.

  • 🇺🇦Ukraine nginex

    Applying a patch from 🐛 Unable to change either the Target or Comparison elements Needs review fixes the issue for me, so the module works well afterwards

  • 🇮🇳India prashant.c Dharamshala

    I also face the same issue on 10.3.x. I will also try to review this MR. Thanks!

  • 🇮🇳India ravranjanim Bangalore

    I am also facing same issue while selecting target ID and compression type on manage field state.

  • Status changed to Needs work 16 days ago
  • 🇲🇽Mexico dalin 🇨🇦, 🇲🇽, 🌍

    I can't seem to get this module working on multiple different sites. This MR plus the one in the related issue still didn't work for me. I'm just going to go with custom code for now.

Production build 0.71.5 2024