Cannot select display of view in default value - possible regression

Created on 26 May 2024, 6 months ago
Updated 21 June 2024, 5 months ago

Problem/Motivation

D 10.2.6 php 8.3
Cannot add a default display of the selected view. The dropdown is empty.

TypeError: uasort(): Argument #1 ($array) must be of type array, null given in uasort() (line 65 of core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php).

Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getPluginId() (Line: 50)
Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getInstance() (Line: 101)
Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getSelectionHandler() (Line: 97)
Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator->validate() (Line: 202)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateConstraints() (Line: 154)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode() (Line: 106)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validate() (Line: 93)
Drupal\Core\TypedData\Validation\RecursiveValidator->validate() (Line: 132)
Drupal\Core\TypedData\TypedData->validate() (Line: 307)
Drupal\Core\Field\FieldItemList->defaultValuesFormValidate() (Line: 377)
Drupal\field_ui\Form\FieldConfigEditForm->validateForm()
call_user_func_array() (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers() (Line: 275)
Drupal\Core\Form\FormValidator->doValidateForm() (Line: 118)
Drupal\Core\Form\FormValidator->validateForm() (Line: 593)
Drupal\Core\Form\FormBuilder->processForm() (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult() (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

Proposed resolution

I just had to reapply the patch https://www.drupal.org/project/viewfield/issues/3381787 🐛 Getting PHP errors when setting default value Fixed .
Then I got it to work.

There may be a regression compared to Beta7.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇦🇹Austria maxilein

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

Merge Requests

Comments & Activities

  • Issue created by @maxilein
  • 🇦🇹Austria maxilein

    - Installing drupal/viewfield (3.0.0-beta8): Extracting archive
    - Applying patches for drupal/viewfield
    https://www.drupal.org/files/issues/2023-08-21/3381787.patch (errors when setting default value for the field)

  • Assigned to sourav_paul
  • Issue was unassigned.
  • 🇮🇳India sourav_paul Kolkata

    Tried to regenerate the issue from the given scenario, not getting the issue in D10.2.6 with PHP8.3.
    Attaching screen-recording for reference : Click to see

  • 🇺🇸United States danflanagan8 St. Louis, US

    Hi @maxilein. Thanks for the report. I reproduced easily. Not able to set a default value. Lots of console logs and db logs and a WSOD on save. Ouch! Clearly there's extreme bugginess with setting a default value.

    I have to say I'm very confused as to how the patch https://www.drupal.org/files/issues/2023-08-21/3381787.patch would fix this. That patch sets a handler on the storage, but the handler is related to the field config, not the field storage. So I'm confused.

    I think Major is the right priority for this. I don't know that it's a true regression since beta7 had similar (if no identical) problems setting a default value.

  • 🇺🇸United States oheller

    I have success with the defaults after updating from beta7 to beta8, but I still have the 3381787.patch applied.
    Below is the code after it's applied. While debugging I noticed that the 2nd defaultStorageSettings() is never hit. Which is why applying the patch works.

    If remove the patch I get an error. If I move the 'target_type' => 'view' into the 2nd function and delete the first, I get an error.

      /**
       * {@inheritdoc}
       */
      public static function defaultStorageSettings() {
        return [
          'target_type' => 'view',
          'handler' => 'default:view',
        ];
      }
    
      /**
       * {@inheritdoc}
       */
      public static function defaultFieldSettings() {
        return [
          'force_default' => 0,
          'allowed_views' => [],
          'allowed_display_types' => ['block' => 'block'],
          'handler' => 'default:view',
        ] + parent::defaultFieldSettings();
      }
    

    After getting the WSOD + error, when I go back to the Manage fields screen I see the following error. I'm not sure if it's related.

    Deprecated function: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getInstance() (line 45 of core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php).
    Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getInstance(Array) (Line: 101)
    Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getSelectionHandler(Object, Object) (Line: 97)
    Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator->validate(Object, Object) (Line: 202)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateConstraints(Object, '0000000000000ee20000000000000000', Array) (Line: 154)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object, Array, 1) (Line: 106)
    Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validate(Object, NULL, NULL) (Line: 93)
    Drupal\Core\TypedData\Validation\RecursiveValidator->validate(Object) (Line: 132)
    Drupal\Core\TypedData\TypedData->validate() (Line: 307)
    Drupal\Core\Field\FieldItemList->defaultValuesFormValidate(Array, Array, Object) (Line: 377)
    Drupal\field_ui\Form\FieldConfigEditForm->validateForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 82)
    Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
    Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'field_config_edit_form') (Line: 118)
    Drupal\Core\Form\FormValidator->validateForm('field_config_edit_form', Array, Object) (Line: 593)
    Drupal\Core\Form\FormBuilder->processForm('field_config_edit_form', Array, Object) (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    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: 121)
    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)
    
  • 🇷🇺Russia DD 85

    I'm working on creating a new website. And today, for the first time, I downloaded and installed the Viewfield module for this site.
    As described above, I encountered two errors:
    Deprecated function: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getInstance() (line 45 of \core\lib\Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager.php)
    TypeError: uasort(): Argument #1 ($array) must be of type array, null given in uasort() (line 65 of \core\lib\Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager.php).

    I found that there is no patch in the release of viewfield 8.x-3.0-beta 8 https://www.drupal.org/project/viewfield/issues/3381787#comment-15199519 🐛 Getting PHP errors when setting default value Fixed
    The viewfield 8.x-3.x-dev 8 May 2024 development release does not have this patch either.

    I applied this patch manually by adding a line
    'handler' => 'default:view',
    and it helped me.
    The fix is working, but it has not yet been applied to any release version.

  • 🇦🇹Austria maxilein

    But it is "working" for the wrong reasons...

  • 🇷🇺Russia DD 85

    At the moment, it's better than not working at all!

  • Merge request !13Resolve #3449950 "Cannot select display" → (Merged) created by danflanagan8
  • Status changed to Needs review 5 months ago
  • 🇺🇸United States danflanagan8 St. Louis, US

    I just opened an MR that I think addresses the bug.

    I'm honestly pretty new to this module and haven't used it a ton, but it seems like we are doing things in field settings that might be more appropriate as handler settings for a custom entity reference selection handler. The root of this bug seems ot be that the default selection handler is being run even though it hasn't been configured properly and is (completely?) useless for us. The field widget is doing a lot of things that the selection plugin might be more appropriate for.

    For now though just updating the settings form as in the MR should be completely undisruptive and seems to fix things.

  • 🇺🇸United States danflanagan8 St. Louis, US

    Note that I'm seeing a core bug surface: 🐛 Querying with NULL values results in warning mb_strtolower(): Passing null to parameter is deprecated Needs work

    So if you get Deprecated function: mb_strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Config\Entity\Query\Condition->compile() (line 39 of /var/www/html/core/lib/Drupal/Core/Config/Entity/Query/Condition.php) when testing this out.

  • 🇫🇮Finland sthomen

    Great that you're on the ball at least, @danflanagan8 :-)

    I spent some time yesterday looking a the SelectionPluginManager to see how my adding 'handler' => 'default:view' to the (default) settings but not the (default) settings makes the problem go away and I really didn't get far.

    The $base_plugin_id parameter to SelectionPluginManager->getPluginId() is sometimes NULL because the instance created by SelectionPluginManager->getInstance() is sometimes constructed with an $options array in getSelectionHandler (either an empty array or the contents of 'handler_settings' from the field definition) without a 'handler' key, which should be the field definition's 'handler' setting. The handler is obviously required, but somehow isn't always present.

    It seems this happens when the SelectionPluginManager is called in the ValidReferenceConstraintValidator (phew, we're really Enterprising here)

    In the working case (i.e. field settings page loads), 'handler' and 'handler_settings' are set

    Drupal\field\Entity\FieldConfig
     ...
      settings => [
        "force_default" => false
        "allowed_views" => ...
        "allowed_display_types" => ...
        "handler" => "default:view"
        "handler_settings" => []
      ]
      ...
    

    but in the non-working case (selecting a view from the dropdown) they are not

    Drupal\field\Entity\FieldConfig
     ...
      settings => [
        "force_default" => 0
        "allowed_views" => ...
        "allowed_display_types" => ...
      ]
     ...
    

    This comment turned out to be a bit of a stream-of-consciousness, but I wanted to share my poking around.

  • 🇺🇸United States danflanagan8 St. Louis, US

    @sthomen, thanks for adding those thoughts!

    The MR I opened has the essential function (though it's not obvious!) of assuring that `target_bundles` on the handler settings gets set to NULL rather than an empty array. NULL means that anything is allowed whereas an empty array means that nothing is allowed (even though views don't have bundles!).

    I suspect that having `handler_settings` itself explicitly set to an empty array as you saw in your testing has the same effect. There's probably two arrays getting +'d somewhere.

    If you ave time to test out the MR, I'd really value your review. Cheers!

  • Status changed to Needs work 5 months ago
  • 🇫🇮Finland sthomen

    This looks like a good enough solution to me, however there seems to have cropped up some nits not directly related to the change;

    - The AJAX response contains an extra optgroup around the displays, this is only cosmetic but still might be worth looking at

    - I saw a couple of JS errors from disable-form-elements.js where doesn't seem to take into account that an ajax instance in Drupal's list might be null. In my experience this happens when an ajax trigger has been updated. Just checking for the instance being null should be sufficient. I would say this should not be fixed in this MR since it really is unrelated.

  • Status changed to Needs review 5 months ago
  • 🇺🇸United States danflanagan8 St. Louis, US

    Hi @sthomen

    The optgroup appears to be by design in ViewfieldWidgetSelect::ajaxGetDisplayOptions

    I noticed and ignored that console log too. I'm still seeing it when I install beta7 though. I wonder if It's something I introduced while trying to do D10 compatibility. See #21 and #22 on 📌 Automated Drupal 10 compatibility fixes Fixed

    I'll open up a new issue that handle that fix.

    If you (or someone else) gives the MR an RTBC I'll put out a new release.

  • Status changed to RTBC 5 months ago
  • 🇫🇮Finland sthomen

    The optgroup appears to be by design in ViewfieldWidgetSelect::ajaxGetDisplayOptions

    Yikes! It's mashing together markup strings, I thought we were past that by now :-)

    This all looks good to go to me. It'd be great to have @jannakha look too since they seemed to have success with the handler being set in defaultFieldSettings but I'll go with RTBC so we can move on.

  • Pipeline finished with Skipped
    5 months ago
    #192971
  • Status changed to Fixed 5 months ago
  • 🇺🇸United States danflanagan8 St. Louis, US

    Thanks for the work on this one, @sthomen!

  • 🇦🇹Austria maxilein

    Thank you!
    Is it in the beta9 or only in dev version?

  • 🇺🇸United States danflanagan8 St. Louis, US

    Should be in beta9.

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

Production build 0.71.5 2024