Commit e11af747 authored by webchick's avatar webchick

Issue #1827424 by EclipseGc, tim.plunkett, Fabianx, dawehner: Fixed Parse annotations recursively.

parent 6f32687e
......@@ -36,14 +36,32 @@ class Plugin implements AnnotationInterface {
* classed annotations that were used.
*/
public function __construct($values) {
$this->definition = $this->parse($values);
}
/**
* Parses an annotation into its definition.
*
* @param array $values
* The annotation array.
*
* @return array
* The parsed annotation as a definition.
*/
protected function parse(array $values) {
$definitions = array();
foreach ($values as $key => $value) {
if ($value instanceof AnnotationInterface) {
$this->definition[$key] = $value->get();
$definitions[$key] = $value->get();
}
elseif (is_array($value)) {
$definitions[$key] = $this->parse($value);
}
else {
$this->definition[$key] = $value;
$definitions[$key] = $value;
}
}
return $definitions;
}
/**
......
......@@ -31,6 +31,15 @@ public function setUp() {
'color' => 'green',
'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Apple',
),
'banana' => array(
'id' => 'banana',
'label' => 'Banana',
'color' => 'yellow',
'uses' => array(
'bread' => t('Banana bread'),
),
'class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Banana',
),
'cherry' => array(
'id' => 'cherry',
'label' => 'Cherry',
......
<?php
/**
* @file
* Contains \Drupal\plugin_test\Plugin\plugin_test\fruit\Banana.
*/
namespace Drupal\plugin_test\Plugin\plugin_test\fruit;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* @Plugin(
* id = "banana",
* label = "Banana",
* color = "yellow",
* uses = {
* "bread" = @Translation("Banana bread")
* }
* )
*/
class Banana {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment