Using $form_state->getValue() in BlockBase's blockForm throws "subform and parent form must contain the #parents property" exception

Created on 10 September 2016, over 8 years ago
Updated 20 May 2024, 8 months ago

Placing a block on block structure page (Zurb Foundation OR Bartik) causes the following error:

RuntimeException: The subform and parent form must contain the #parents property, which must be an array. Try calling this method from a #process callback instead. in Drupal\Core\Form\SubformState->getParents() (line 76 of /Users/maria.mcdowell/Sites/devdesktop/eemmcdowell-test/docroot/core/lib/Drupal/Core/Form/SubformState.php).

[EDITED]
I tested against multiple blocks. Any block in the category "content" fails to load, as does "user" blocks. My initial test was against what I thought was a view block, but it turns out that it was the content block created by a module, probably CTools, of the same name.

Note that the Entity (user and content) blocks work without error, so it is not all things created by CTools.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Form 

Last updated 1 day ago

Created by

🇺🇸United States mariagwyn

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India saurabh.tripathi.cs

    Is there a patch for D10?
    i have changed #56 a bit to match with D10

      /**
       * {@inheritdoc}
       */
      public function &getValues() {
        $exists = NULL;
        if ($this->isProcessingInput()) {
          $values = &NestedArray::getValue(parent::getValues(), $this->getParents('#parents'), $exists);
        }
        else {
          @trigger_error("Please don't.", E_USER_DEPRECATED);
        }
        if (!$exists) {
          $values = [];
        }
        if (!is_array($values)) {
          throw new \UnexpectedValueException('The form state values do not belong to the subform.');
        }
    
        return $values;
      }
    
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.6
    last update 7 months ago
    Custom Commands Failed
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.6
    last update 7 months ago
    Custom Commands Failed
  • 🇮🇳India bunty badgujar Delhi

    I am adding patch for D-10.4.x branch.

  • 🇷🇴Romania bbu23

    I have the following setup:

    1. A configuration entity that builds the add form using ajax. The field that triggers ajax is a plugin select list.
    2. When a plugin is selected, the form includes subforms of the plugins, using ajax. All okay.
    3. If one of the plugin's form (the subform) is using ajax, then the error can appear when attempting to retrieve values from the SubFormState in the build form area. The ajax calls within the plugin form will also have the form state of the parent.

    It seems like ajax inside subform of an ajax loaded parent form does not work well.

Production build 0.71.5 2024