Problem/Motivation

In the following annotation, the @Translation annotation is used both on the top level for 'label', but also nested in 'view_modes' -> 'full' -> 'label'.
Currently this does not work, preventing any nested values from being transltations.

use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;

/**
 * Defines the user entity class.
 *
 * @Plugin(
 *   id = "user",
 *   label = @Translation("User"),
 *   module = "user",
 *   view_modes = {
 *     "full" = {
 *       "label" = @Translation("User account"),
 *       "custom_settings" = FALSE
 *     }
 *   }
 * )
 */
class User extends Entity {
  //...
}

Proposed resolution

Parse the annotations recursively, by splitting the actual parsing code out of Drupal\Core\Annotation\Plugin::__construct() and into a dedicated method.

Remaining tasks

n/a

User interface changes

n/a

API changes

Adds a new protected method Drupal\Core\Annotation\Plugin::parse().

Comments

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new1.1 KB
sun’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, makes sense.

eclipsegc’s picture

I was coming to RTBC this as well. Blocks needs it and it is in fact straight out of my patch for blocks, so ++ from me.

tim.plunkett’s picture

Oh yes, for the committers, @EclipseGc should get credit on this commit.

eclipsegc’s picture

not then intention of that comment, but thanks :-)

fabianx’s picture

+1 for RTBC of this, nice patch.

fabianx’s picture

StatusFileSize
new1.13 KB

Cosmetical touch:Added declaration of $definitions before loop.

Does not change RTBC status.

dawehner’s picture

StatusFileSize
new1.13 KB
+++ b/core/lib/Drupal/Core/Annotation/Plugin.phpundefined
@@ -36,14 +36,33 @@ class Plugin implements AnnotationInterface {
+    $definitions=array();

I'm sorry, please don't put me in the commit message.

tim.plunkett’s picture

StatusFileSize
new1.13 KB

Let's not put either of you in there ;)

Ahem.

Status: Reviewed & tested by the community » Needs work
Issue tags: -Plugin system

The last submitted patch, drupal-1827424-9.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
Issue tags: +Plugin system

#9: drupal-1827424-9.patch queued for re-testing.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Was RTBC before, just had some minor style corrections, which look correct.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

We should get test coverage for this.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new2.87 KB
new1.74 KB

Here we are.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Noone can argue with more fruit in Drupal :-)
Assuming this comes back red/green, this is RTBC.

tim.plunkett’s picture

Priority: Normal » Major

This blocks #1535868: Convert all blocks into plugins (that patch includes this one), so bumping the priority.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

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