hook_options_list_alter lacks $context['widget']

Created on 8 May 2020, over 4 years ago
Updated 22 February 2023, over 1 year ago

Problem/Motivation

When using hook_options_list_alter, the most natural thing is to use widget third party settings.
Example: In the contrib module betternone, i use widget TPS to move and/or rename the "- None -" option.
Not having that TPS makes the hook lame. Using other hooks makes the implementation brittle and needs a lot of boilerplate code.
Therefor i consider this as a bug.

Proposed resolution

Trivially add widget object to hook context.

Remaining tasks

Code, commit.

User interface changes

None.

API changes

Pure Addition.

Data model changes

None.

Release notes snippet

hook_options_list_alter now containt the widget object in its context.

πŸ› Bug report
Status

Fixed

Version

10.1 ✨

Component
OptionsΒ  β†’

Last updated 9 days ago

No maintainer
Created by

πŸ‡©πŸ‡ͺGermany geek-merlin Freiburg, Germany

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Even though I submitted the last patch I only changed a space error. So this review is of #20 really

    Change record looks good. The example is great addition!

    Also like the test coverage as it shows an example of altering it on a live instance.

    I think this is good to move on for core committer review.

  • Status changed to Fixed over 1 year ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Committed 13fb795 and pushed to 10.1.x. Thanks!

    diff --git a/core/modules/options/tests/src/Functional/OptionsWidgetsTest.php b/core/modules/options/tests/src/Functional/OptionsWidgetsTest.php
    index 679a6620013..5838a06e9ba 100644
    --- a/core/modules/options/tests/src/Functional/OptionsWidgetsTest.php
    +++ b/core/modules/options/tests/src/Functional/OptionsWidgetsTest.php
    @@ -651,8 +651,11 @@ public function testOptionsListAlter() {
     
         // Display form: check that _none options are present.
         $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
    -    $this->assertNotEmpty($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-1', ':label' => '- None -']), 'A test select has a "None" choice with default label.');
    -    $this->assertNotEmpty($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-4', ':label' => '- Please select something -']), 'A test select has a "None" choice with altered label.');
    +    $xpath = '//select[@id=:id]//option[@value="_none" and text()=:label]';
    +    $xpath_args = [':id' => 'edit-card-1', ':label' => '- None -'];
    +    $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery($xpath, $xpath_args));
    +    $xpath_args = [':id' => 'edit-card-4', ':label' => '- Please select something -'];
    +    $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery($xpath, $xpath_args));
     
         // Display form: check that options are displayed correctly.
         $this->assertSession()->optionExists('card_1', 0);
    

    Given we're asserting that an element exists let's use the correct assertion - you get better and more consistent error messages. Fixed on commit.

    • alexpott β†’ committed defcb862 on 10.1.x
      Issue #3134618 by geek-merlin, smustgrave, Matroskeen, Kristen Pol,...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024