Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
If a block defines contexts in the annotation, the block edit form will add a context mapping form element to be used to map available contexts to the ones the block can use. This is fine.
However, if the block defines a non-required context and the available contexts are not suitable for that block (none are valid for it), the block form context mapper will be an empty select list (no option to choose from).
Proposed resolution
Do not show the context mapper form element if there are no options to choose from.
Remaining tasks
- Create patch to adjust
ContextAwarePluginAssignmentTrait::addContextAssignmentElement()
so that it handles this case. - Test
User interface changes
Context mapper will only show if there are (valid) contexts available to be mapped.
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#19 | 2809305-19.patch | 3.11 KB | Upchuk |
#19 | interdiff-2809305-19.txt | 820 bytes | Upchuk |
#17 | interdiff-2809305-17.txt | 849 bytes | Upchuk |
#17 | 2809305-17.patch | 2.92 KB | Upchuk |
#14 | interdiff-2809305-14.txt | 3.04 KB | Upchuk |
Comments
Comment #2
Upchuk CreditAttribution: Upchuk at Wunder commentedAnd the patch.
Comment #4
Upchuk CreditAttribution: Upchuk at Wunder commentedComment #6
BerdirNot 100% sure, there are also issues that suggest to show that form element always, otherwise you don't even know that you could provide something.
this should afaik be a single line.
not needed.
Comment #7
jofitz CreditAttribution: jofitz at ComputerMinds commentedRe-roll including both changes suggested by @Berdir in #6.
Comment #8
Pavan B S CreditAttribution: Pavan B S at Valuebound commentedMade minor change of short array syntax, applying the patch, please review
Comment #12
Upchuk CreditAttribution: Upchuk as a volunteer commentedRerolling, let's see.
Comment #14
Upchuk CreditAttribution: Upchuk as a volunteer commentedAha, it seems #3014949: Deprecate 'context' on Block and Condition plugin annotations in favor of 'context_definitions' changed the context definitions annotation :) Here is the updated patch.
Comment #16
tim.plunkettThe patch is passing a message as the second param of fieldNotExists(), but that's not supported. Just removing that should be enough.
Comment #17
Upchuk CreditAttribution: Upchuk as a volunteer commentedAh yes, indeed. Missed that, thanks!
Comment #18
tim.plunkettSorry I didn't ask for this sooner. But can you add a comment here explaining what this is checking for? Essentially that if options is 0 it should never show, and that it should only show for the 1 option if it is optional. (Which makes this logic weird, since it's the inverse).
The original issue that added the OR case should have included a comment but didn't and so it falls to this issue.
Comment #19
Upchuk CreditAttribution: Upchuk as a volunteer commentedAlrighty, here we are.
Comment #20
tim.plunkettThanks!
Comment #21
alexpottCommitted and pushed 55f13aacb5 to 8.7.x and c490e4029c to 8.6.x. Thanks!
Backported to 8.6.x after running
core/modules/block/tests/src/Functional/BlockUiTest.php
locally.Comment #25
super_romeo CreditAttribution: super_romeo commented