Problem/Motivation
\Drupal\Core\Annotation\ContextDefinition::__construct()
always sets the label and the description to NULL because those values are never \Drupal\Core\StringTranslation\TranslatableMarkup
s
The @TranslatableMarkup() is not usable in annotations because it doesn't implement the \Drupal\Component\Annotation\AnnotationInterface
and not marked with @Annotation
So the following condition is always FALSE
:
if (isset($values[$key]) && $values[$key] instanceof TranslatableMarkup) {
Steps to reproduce
I noticed this problem when I wanted to write a Condition plugin with a entity:taxonomy_term
context and in the \Drupal\Core\Condition\ConditionInterface::summary()
I used the following code to get the label of the context but it always returned with NULL
$this->getContextDefinition('taxonomy_term')->getLabel()
Proposed resolution
Use the correct class
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
Comment | File | Size | Author |
---|---|---|---|
#14 | 2916376-14.patch | 2.47 KB | rlmumford |
#10 | 2916376-10.patch | 2.47 KB | rlmumford |
#10 | 2916376-10-failingtest.patch | 1.52 KB | rlmumford |
#2 | drupal-2916376-2-context-definition-label-and-desc.patch | 970 bytes | Sweetchuck |
Comments
Comment #2
SweetchuckComment #9
rlmumfordMade this Major because there's no workaround available.
Comment #10
rlmumfordI've added two patches. One that introduces test coverage (and fails) and another that fixes the issue.
Comment #12
tim.plunkettUgh sorry @Sweetchuck, I don't know how this issue slipped through for so long. Thanks @rlmumford for resurrecting it.
This should be
assertEquals
, and the arguments should be swappedOtherwise, everything is good!
Comment #13
EclipseGc CreditAttribution: EclipseGc commentedI agree, this seems very sensible and obvious.
Comment #14
rlmumfordFixed the nitpick
Comment #15
tim.plunkettThanks!
Comment #16
EclipseGc CreditAttribution: EclipseGc commented++ on rtbc
Comment #17
SweetchuckThanks.
Comment #21
catchCommitted/pushed to 9.2.x, cherry-picked to 9.1.x and 8.9.x, thanks!