Problem/Motivation

On my project with v1.0.1 of required_by_form_mode and Profile module v1.12 installed, I receive ajax errors when trying to add new options to list field during field creation for Profile entities.
I will create a MR with workaround that worked for me but may be not the best solution.

Error trace I see in logs:

InvalidArgumentException: The configuration property settings.allowed_values.0.label.0 doesn't exist. in Drupal\Core\Config\Schema\ArrayElement->get() (regel 95 van /code/web/core/lib/Drupal/Core/Config/Schema/ArrayElement.php).

#0 /code/web/core/lib/Drupal/Core/Config/StorableConfigBase.php(223): Drupal\Core\Config\Schema\ArrayElement->get('settings.allowe...')
#1 /code/web/core/lib/Drupal/Core/Config/StorableConfigBase.php(258): Drupal\Core\Config\StorableConfigBase->castValue('settings.allowe...', Array)
#2 /code/web/core/lib/Drupal/Core/Config/StorableConfigBase.php(258): Drupal\Core\Config\StorableConfigBase->castValue('settings.allowe...', Array)
#3 /code/web/core/lib/Drupal/Core/Config/StorableConfigBase.php(258): Drupal\Core\Config\StorableConfigBase->castValue('settings.allowe...', Array)
#4 /code/web/core/lib/Drupal/Core/Config/StorableConfigBase.php(258): Drupal\Core\Config\StorableConfigBase->castValue('settings.allowe...', Array)
#5 /code/web/core/lib/Drupal/Core/Config/StorableConfigBase.php(258): Drupal\Core\Config\StorableConfigBase->castValue('settings', Array)
#6 /code/web/core/lib/Drupal/Core/Config/Config.php(211): Drupal\Core\Config\StorableConfigBase->castValue(NULL, Array)
#7 /code/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(278): Drupal\Core\Config\Config->save(false)
#8 /code/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(486): Drupal\Core\Config\Entity\ConfigEntityStorage->doSave('profile.field_t...', Object(Drupal\field\Entity\FieldStorageConfig))
#9 /code/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(257): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\field\Entity\FieldStorageConfig))
#10 /code/web/core/lib/Drupal/Core/Entity/EntityBase.php(354): Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object(Drupal\field\Entity\FieldStorageConfig))
#11 /code/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(617): Drupal\Core\Entity\EntityBase->save()
#12 /code/web/modules/contrib/required_by_form_mode/required_by_form_mode.module(132): Drupal\Core\Config\Entity\ConfigEntityBase->save()
#13 [internal function]: required_by_form_mode_field_config_edit_form_builder('field_config', Object(Drupal\field\Entity\FieldConfig), Array, Object(Drupal\Core\Form\FormState))
#14 /code/web/core/lib/Drupal/Core/Entity/EntityForm.php(307): call_user_func_array('required_by_for...', Array)
#15 /code/web/core/lib/Drupal/Core/Entity/EntityForm.php(171): Drupal\Core\Entity\EntityForm->buildEntity(Array, Object(Drupal\Core\Form\FormState))
#16 /code/web/core/modules/field_ui/src/Form/FieldConfigEditForm.php(278): Drupal\Core\Entity\EntityForm->afterBuild(Array, Object(Drupal\Core\Form\FormState))
#17 [internal function]: Drupal\field_ui\Form\FieldConfigEditForm->afterBuild(Array, Object(Drupal\Core\Form\FormState))
#18 /code/web/core/lib/Drupal/Core/Form/FormBuilder.php(1082): call_user_func_array(Array, Array)
#19 /code/web/core/lib/Drupal/Core/Form/FormBuilder.php(579): Drupal\Core\Form\FormBuilder->doBuildForm('field_config_ed...', Array, Object(Drupal\Core\Form\FormState))
#20 /code/web/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm('field_config_ed...', Array, Object(Drupal\Core\Form\FormState))
#21 /code/web/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\field_ui\Form\FieldConfigEditForm), Object(Drupal\Core\Form\FormState))
#22 /code/web/core/modules/field_ui/src/Controller/FieldConfigAddController.php(63): Drupal\Core\Entity\EntityFormBuilder->getForm(Object(Drupal\field\Entity\FieldConfig), 'default', Array)
#23 [internal function]: Drupal\field_ui\Controller\FieldConfigAddController->fieldConfigAddConfigureForm('profile', 'field_test_list')
#24 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#25 /code/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#26 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#27 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#28 /code/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#29 /code/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#30 /code/web/modules/contrib/simple_oauth/src/HttpMiddleware/BasicAuthSwap.php(68): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /code/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /code/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /code/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#34 /code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#35 /code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#36 /code/vendor/asm89/stack-cors/src/Cors.php(53): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#37 /code/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Asm89\Stack\Cors->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#38 /code/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#39 /code/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#40 /code/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#41 /code/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#42 /code/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#43 {main}

Steps to reproduce

Have required_by_form_mode and profile modules installed.
Try to create field of type List for Profile entity type.
Go thru creation steps until options configuration.
Try to add new option

Proposed resolution

Make sure that module's code is not run within ajax requests.

Remaining tasks

Review and test

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

aylis created an issue. See original summary.

aylis’s picture

Status: Active » Needs review

Created MR with changes that fixed error during list field creation for Profile entity

aylis’s picture

Status: Needs review » Needs work

Apologies, patch I've provided don't solve issue completely, it just let me to add list items but submission of the form still leads to fatal error. Will investigate possible solution further

aylis’s picture

Status: Needs work » Needs review

I've updated an MR: looks like storage config save in this module's callback is not needed as save it being run later under the hood and this additional save was cause of errors

  • abdulaziz zaid committed f5881429 on 1.0.x
    Issue #3535487: Fix error upon adding new list items
    
    Move field storage...
abdulaziz zaid’s picture

Thanks for reporting this. Fixed in f5881429 — moved $storage->save() to a submit handler so it doesn't run during AJAX rebuilds. Available in 1.0.x-dev.

abdulaziz zaid’s picture

Status: Needs review » Fixed

Fixed and released in 1.0.4.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • abdulaziz zaid committed 744c554f on 1.0.x
    Issue #3535487: Fix entity builder to skip AJAX rebuilds
    
    Made-with:...
abdulaziz zaid’s picture

Status: Fixed » Needs work

  • abdulaziz zaid committed 1671bdc2 on 1.0.x
    Issue #3535487: Support Drupal 9, 10, and 11 by conditionally saving...
abdulaziz zaid’s picture

Status: Needs work » Fixed

Fixed in version 3.0.0. The $storage->save() call was causing errors during AJAX requests. It is now only called on Drupal < 10.2. Thanks for reporting!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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