Problem/Motivation
Many implementations of \Drupal\Core\Plugin\PluginFormInterface assume they are used as top-level forms because of the fact they call FormStateInterface::getValue() directly rather than getting the value from the form's state based on the plugin form's position in the parent form. This requires using NestedArray and $form['#parents'].
This works fine in core because most plugin forms are only used in one single way, but this obviously fails when embedding plugin forms in different parent forms. This is exactly what Plugin does.
Proposed resolution
- Improve
PluginFormInterface's documentation to explicitly state that plugin forms are meant to be embedded, and that the$formparameters only contain the plugin forms' elements. See #2532970: PluginFormInterface must document $form means the plugin's own elements. - Improve
PluginFormInterface's documentation to explicitly state that plugin forms are meant to be embedded, and that extra measures must be taken to reliably retrieve submitted form values. See #2537732: PluginFormInterface must have access to the complete $form_state (introduce SubFormState for embedded forms). - Fix broken implementations:
Remaining tasks
Find all broken implementations and create separate issues for them.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #1
xanoComment #2
xanoComment #3
bojanz commentedI agree completely. The current situation is a hack that will only lead to further bugs.
Comment #4
xanoSee #2537732: PluginFormInterface must have access to the complete $form_state (introduce SubFormState for embedded forms) for a patch, which is blocked by #2547581: Missing configuration schemas for condition plugins.
Comment #8
stone_d commentedI get this error :(
TypeError: Argument 1 passed to Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemBase::setContainedPluginConfiguration() must be of the type array, string given, called in /var/www/virtual/picstar_dp/modules/plugin/src/Plugin/Field/FieldType/PluginCollectionItemBase.php on line 202 in Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemBase->setContainedPluginConfiguration() (line 108 of /var/www/virtual/picstar_dp/modules/plugin/src/Plugin/Field/FieldType/PluginCollectionItemBase.php) #0 /var/www/virtual/picstar_dp/modules/plugin/src/Plugin/Field/FieldType/PluginCollectionItemBase.php(202): Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemBase->setContainedPluginConfiguration('a:5:{s:4:"name"...') #1 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/TypedData/TypedDataManager.php(195): Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemBase->setValue(Array, false) #2 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/Field/FieldTypePluginManager.php(82): Drupal\Core\TypedData\TypedDataManager->getPropertyInstance(Object(Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemList), 0, Array) #3 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/Field/FieldItemList.php(40): Drupal\Core\Field\FieldTypePluginManager->createFieldItem(Object(Drupal\plugin\Plugin\Field\FieldType\PluginCollectionItemList), 0, Array) #4 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php(66): Drupal\Core\Field\FieldItemList->createItem(0, Array) #5 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/Field/FieldItemList.php(118): Drupal\Core\TypedData\Plugin\DataType\ItemList->setValue(Array, false) #6 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/TypedData/TypedDataManager.php(106): Drupal\Core\Field\FieldItemList->setValue(Array, false) #7 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(1572): Drupal\Core\TypedData\TypedDataManager->create(Object(Drupal\field\Entity\FieldConfig), Array, 'field_payment_l...', Object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter)) #8 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(175): Drupal\Core\Entity\Sql\SqlContentEntityStorage->readFieldItemsToPurge(Object(Drupal\field\Entity\FieldConfig), 50) #9 /var/www/virtual/picstar_dp/core/modules/field/field.purge.inc(96): Drupal\Core\Entity\ContentEntityStorageBase->purgeFieldData(Object(Drupal\field\Entity\FieldConfig), 50) #10 /var/www/virtual/picstar_dp/core/modules/field/field.module(167): field_purge_batch(50) #11 [internal function]: field_cron() #12 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/Extension/ModuleHandler.php(391): call_user_func_array('field_cron', Array) #13 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/Cron.php(223): Drupal\Core\Extension\ModuleHandler->invoke('field', 'cron') #14 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/Cron.php(122): Drupal\Core\Cron->invokeCronHandlers() #15 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/ProxyClass/Cron.php(75): Drupal\Core\Cron->run() #16 /var/www/virtual/picstar_dp/core/modules/automated_cron/src/EventSubscriber/AutomatedCron.php(65): Drupal\Core\ProxyClass\Cron->run() #17 /var/www/virtual/picstar_dp/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): Drupal\automated_cron\EventSubscriber\AutomatedCron->onTerminate(Object(Symfony\Component\HttpKernel\Event\PostResponseEvent), 'kernel.terminat...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher)) #18 /var/www/virtual/picstar_dp/vendor/symfony/http-kernel/HttpKernel.php(84): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.terminat...', Object(Symfony\Component\HttpKernel\Event\PostResponseEvent)) #19 /var/www/virtual/picstar_dp/vendor/stack/builder/src/Stack/StackedHttpKernel.php(32): Symfony\Component\HttpKernel\HttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse)) #20 /var/www/virtual/picstar_dp/core/lib/Drupal/Core/DrupalKernel.php(634): Stack\StackedHttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse)) #21 /var/www/virtual/picstar_dp/index.php(22): Drupal\Core\DrupalKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse)) #22 {main}.Comment #15
andypostComment #18
quietone commentedThere is one issue child left in this Meta. We have a practice of allowing metas to be closed when there is only one remaining item. I am doing that now.
This is also not a bug report, I am changing it to a plan.