Module seems incompatible with Drupal 10.2

Created on 28 March 2024, 3 months ago
Updated 30 April 2024, about 2 months ago

Problem/Motivation

Adding a list field to a node with D10.2 will result in validation errors and later on the field storage can't be saved.

Steps to reproduce

1. Install list_predefined_options
2. Add a new selection list field to a node type
3. Use List(text) as the type
4. In the field settings form try to select one of the predefined plugins, e.g.Timezones
5. Notice, that the form does not change, in previous versions the allowed values were hidden
6. As the allowed values are still part of the form and contain a required attribute, fill out one of them
7. Hit Save Settings

You'll get 2 errors:

The javascript console contains:

[Error] AjaxError: 
An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /admin/structure/types/manage/article/add-field/node/field_test?destinations%5B0%5D%5Broute_name%5D=entity.node.field_ui_fields&destinations%5B0%5D%5Broute_parameters%5D%5Bentity_type%5D=node&destinations%5B0%5D%5Broute_parameters%5D%5Bfield_name%5D=field_test&destinations%5B0%5D%5Broute_parameters%5D%5Bnode_type%5D=article&destinations%5B1%5D=/admin/structure/types/manage/article/fields/add-field
StatusText: error
ResponseText: The website encountered an unexpected error. Try again later.Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::getThirdPartySetting() in list_predefined_options_allowed_values() (line 110 of modules/contrib/list_predefined_options/list_predefined_options.module). options_allowed_values(Object, Object) (Line: 65)
Drupal\options\Plugin\Field\FieldType\ListItemBase->getSettableOptions(Object) (Line: 143)
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions(Object) (Line: 34)
Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget->formElement(Object, 0, Array, Array, Object) (Line: 459)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 101)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 287)
Drupal\Core\Field\FieldItemList->defaultValuesForm(Array, Object) (Line: 230)
Drupal\field_ui\Form\FieldConfigEditForm->form(Array, Object) (Line: 107)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('field_config_edit_form', Object) (Line: 375)
Drupal\Core\Form\FormBuilder->rebuildForm('field_config_edit_form', Object, Array) (Line: 633)
Drupal\Core\Form\FormBuilder->processForm('field_config_edit_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'default', Array) (Line: 63)
Drupal\field_ui\Controller\FieldConfigAddController->fieldConfigAddConfigureForm('node', 'field_test')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

	(anonymous function) (js_Wu9DoxPFb1979Ym3fM0LQ8rgU-BI-_NvI9DRwB9WqXU.js:250:13550)
	complete (js_Wu9DoxPFb1979Ym3fM0LQ8rgU-BI-_NvI9DRwB9WqXU.js:250:6041)
	(anonymous function) (js_Wu9DoxPFb1979Ym3fM0LQ8rgU-BI-_NvI9DRwB9WqXU.js:289:3569)
	c (js_Wu9DoxPFb1979Ym3fM0LQ8rgU-BI-_NvI9DRwB9WqXU.js:3:25310)
	fireWith (js_Wu9DoxPFb1979Ym3fM0LQ8rgU-BI-_NvI9DRwB9WqXU.js:3:26055)
	l (js_Wu9DoxPFb1979Ym3fM0LQ8rgU-BI-_NvI9DRwB9WqXU.js:3:77919)
	(anonymous function) (js_Wu9DoxPFb1979Ym3fM0LQ8rgU-BI-_NvI9DRwB9WqXU.js:3:80267)

Proposed resolution

Not sure how to tackle that.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany stmh

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

Merge Requests

Comments & Activities

  • Issue created by @stmh
  • Assigned to aleksandr.s
  • 🇺🇦Ukraine aleksandr.s

    oleksandr.s changed the visibility of the branch list_predefined_options-3436776 to hidden.

  • 🇮🇳India dineshkumarbollu

    +1 encountering same error.

  • 🇺🇦Ukraine aleksandr.s

    Hi, here is patch related to this issue.

    1. In patch I modified key for '#states' and added 'table' key. As now, drupal builds field storage settings form using table element $element['allowed_values']['table'] . https://git.drupalcode.org/project/drupal/-/blob/10.2.x/core/modules/opt...

    2. In patch I modified 'name' selector of list_predefined_options_plugin_id to control states of allowed_values as now, drupal using subform key wrapper. https://git.drupalcode.org/project/drupal/-/blob/10.2.x/core/modules/fie...

  • Issue was unassigned.
  • Status changed to Needs review 3 months ago
  • 🇩🇪Germany stmh

    thanks for the patch, but unfortunately it is not working on my end.

    See the screen-recording

  • Status changed to Needs work 3 months ago
  • 🇺🇦Ukraine aleksandr.s

    Hi @stmh, thank you for reviewing and testing.

    Here is new a patch.

  • Status changed to Needs review 3 months ago
  • Status changed to Needs work 3 months ago
  • 🇬🇧United Kingdom joachim

    Good work figuring this out!

    Why the mix of patch and MR though? I've reviewed the patch but I've just seen there's an MR too :(

    Please just stick to one channel -- ideally a MR.

    1. +++ b/list_predefined_options.info.yml
      @@ -4,7 +4,7 @@ description: 'Provides reusable, predefined options for list fields'
      -core_version_requirement: ^8 || ^9 || ^10
      +core_version_requirement: ^10.2
      

      What's the convention on our release number if we drop support for a core major?

    2. +++ b/list_predefined_options.module
      @@ -5,17 +5,19 @@
        * Implements hook_form_FORM_ID_alter(): field_storage_config_edit_form.
      

      This needs updating too.

    3. +++ b/list_predefined_options.module
      @@ -5,17 +5,19 @@
      -function list_predefined_options_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
      +function list_predefined_options_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
      

      Urgh... Yes, core forms aren't part of the API, but this is a pain :(

    4. +++ b/list_predefined_options.module
      @@ -36,8 +38,29 @@ function list_predefined_options_form_field_storage_config_edit_form_alter(&$for
      +    // Form API '#states' functionality based on some classes.
      +    // So add these classes.
      +    // @see state.js.
      

      Can you explain more why we need to add these manually? That sounds like a bug in core to me.

    5. +++ b/list_predefined_options.module
      @@ -45,38 +68,75 @@ function list_predefined_options_form_field_storage_config_edit_form_alter(&$for
        * Implements hook_ENTITY_TYPE_presave(): field_storage_config
      

      Needs updating.

    6. +++ b/list_predefined_options.module
      @@ -108,6 +168,11 @@ function list_predefined_options_field_storage_config_presave(EntityInterface $e
      +  if ($plugin_id) {
      

      That seems like an unrelated fix?

  • Assigned to joachim
  • 🇬🇧United Kingdom joachim
    +++ b/list_predefined_options.module
    @@ -45,38 +68,75 @@ function list_predefined_options_form_field_storage_config_edit_form_alter(&$for
    -function list_predefined_options_field_storage_config_presave(EntityInterface $entity) {
    +function list_predefined_options_field_config_presave(EntityInterface $entity) {
    

    These CRUD hook changes are wrong -- the 10.2 change is a UI change only. Config settings are still in the same entities.

  • 🇬🇧United Kingdom joachim

    I don't understand this change:

    -    $entity->setSetting('allowed_values_function', 'list_predefined_options_allowed_values');
    
    +    $form_state->setValue(['field_storage', 'subform', 'settings', 'allowed_values_function'], 'list_predefined_options_allowed_values');
    
  • Merge request !410.2 support → (Merged) created by joachim
  • Status changed to Needs review 2 months ago
  • 🇬🇧United Kingdom joachim

    I was struggling to understand all the changes in that MR, so I made a fresh branch, to gradually take changes one by one.

    I've gone for what I think is a simpler approach, of altering the storage settings form as we already did, rather than altering the outer form. I *think* that means that our code doesn't need to be away of the subform-in-form situation, which makes it less brittle.

  • Status changed to RTBC 2 months ago
  • 🇺🇦Ukraine aleksandr.s

    Hi, tested.
    MR4 works for me.

  • 🇩🇪Germany stmh

    hi, MR4 works for me as well!

  • Pipeline finished with Skipped
    2 months ago
    #148259
    • joachim committed 506d0455 on 2.0.x
      Issue #3436776 by oleksandr.s, joachim: Updated form alterations for...
    • joachim committed af6a1dce on 2.0.x
      Issue #3436776 by joachim: Updated core version requirement to mark...
    • joachim committed 28a3270b on 2.0.x
      Revert #3436776 on the 2.0.x branch.
      
      This reverts commit...
  • Status changed to Fixed 2 months ago
  • 🇬🇧United Kingdom joachim

    Fixed. Making a new release on a new 3.0.x branch, since we're dropping support for a major (see https://mglaman.dev/blog/drupal-module-semantic-versioning-drupal-core-s...).

    Also making a new 2.0.0 beta which is marked as incompatible with 10.2, so Composer hopefully installs the right things!

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

Production build 0.69.0 2024