PluginNotFoundException: The "" plugin does not exist

Created on 3 July 2023, over 1 year ago
Updated 11 September 2024, 2 months 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, and when you click on Cancel you end up in the open settings of another field (like Title or Label) ๐Ÿคจ
    Error:
    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)
    Screenshot:
  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 recommended Drupal 10.1 install (with DDEV, PHP 8.1.16), add a boolean field to Article (or any entity 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

Needs review

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
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly kopeboy Milan
  • ๐Ÿ‡ฎ๐Ÿ‡น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 7 months ago
    23 pass, 24 fail
  • Status changed to Needs review 7 months 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.

Production build 0.71.5 2024