Skip to content
Snippets Groups Projects
Commit e11af747 authored by Angie Byron's avatar Angie Byron
Browse files

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

parent 6f32687e
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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 {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment