Problem/Motivation

\Drupal\Core\Annotation\ContextDefinition::__construct() always sets the label and the description to NULL because those values are never \Drupal\Core\StringTranslation\TranslatableMarkups

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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sweetchuck created an issue. See original summary.

Sweetchuck’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

rlmumford’s picture

Priority: Normal » Major

Made this Major because there's no workaround available.

rlmumford’s picture

I've added two patches. One that introduces test coverage (and fails) and another that fixes the issue.

The last submitted patch, 10: 2916376-10-failingtest.patch, failed testing. View results

tim.plunkett’s picture

Issue summary: View changes

Ugh sorry @Sweetchuck, I don't know how this issue slipped through for so long. Thanks @rlmumford for resurrecting it.

+++ b/core/tests/Drupal/KernelTests/Core/Plugin/Annotation/ContextDefinitionTest.php
@@ -25,6 +25,7 @@ public function testConstraints() {
+    $this->assertEqual($definition['context_definitions']['user']->getLabel(), "User Context");

This should be assertEquals, and the arguments should be swapped

Otherwise, everything is good!

EclipseGc’s picture

I agree, this seems very sensible and obvious.

rlmumford’s picture

Fixed the nitpick

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

EclipseGc’s picture

++ on rtbc

Sweetchuck’s picture

Thanks.

  • catch committed 32f249a on 9.2.x
    Issue #2916376 by rlmumford, Sweetchuck, tim.plunkett: The @...

  • catch committed a180fe8 on 9.1.x
    Issue #2916376 by rlmumford, Sweetchuck, tim.plunkett: The @...

  • catch committed 41cc353 on 8.9.x
    Issue #2916376 by rlmumford, Sweetchuck, tim.plunkett: The @...
catch’s picture

Version: 9.2.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x, cherry-picked to 9.1.x and 8.9.x, thanks!

Status: Fixed » Closed (fixed)

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