Commit 48025f92 authored by alexpott's avatar alexpott
Browse files

Issue #2168159 by dawehner: Plugin Derivatives don't work with Objects returned from Annotations.

parent c53879f0
......@@ -27,7 +27,7 @@ abstract class DerivativeBase implements DerivativeInterface {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) {
public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
return $this->derivatives[$derivative_id];
}
......@@ -38,7 +38,7 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
return $this->derivatives;
}
}
......@@ -18,16 +18,17 @@ interface DerivativeInterface {
* @param string $derivative_id
* The derivative id. The id must uniquely identify the derivative within a
* given base plugin, but derivative ids can be reused across base plugins.
* @param array $base_plugin_definition
* The definition array of the base plugin from which the derivative plugin
* is derived.
* @param mixed $base_plugin_definition
* The definition of the base plugin from which the derivative plugin
* is derived. It is maybe an entire object or just some array, depending
* on the discovery mechanism.
*
* @return array
* The full definition array of the derivative plugin, typically a merge of
* $base_plugin_definition with extra derivative-specific information. NULL
* if the derivative doesn't exist.
*/
public function getDerivativeDefinition($derivative_id, array $base_plugin_definition);
public function getDerivativeDefinition($derivative_id, $base_plugin_definition);
/**
* Returns the definition of all derivatives of a base plugin.
......@@ -39,6 +40,6 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin
*
* @see getDerivativeDefinition()
*/
public function getDerivativeDefinitions(array $base_plugin_definition);
public function getDerivativeDefinitions($base_plugin_definition);
}
......@@ -155,17 +155,17 @@ protected function encodePluginId($base_plugin_id, $derivative_id) {
*
* @param string $base_plugin_id
* The base plugin id of the plugin.
* @param array $base_definition
* @param mixed $base_definition
* The base plugin definition to build derivatives.
*
* @return \Drupal\Component\Plugin\Derivative\DerivativeInterface|null
+ * A DerivativeInterface or NULL if none exists for the plugin.
+ *
+ * @throws \Drupal\Component\Plugin\Exception\InvalidDerivativeClassException
+ * Thrown if the 'derivative' class specified in the plugin definition does
+ * not implement \Drupal\Component\Plugin\Derivative\DerivativeInterface.
* A DerivativeInterface or NULL if none exists for the plugin.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidDerivativeClassException
* Thrown if the 'derivative' class specified in the plugin definition does
* not implement \Drupal\Component\Plugin\Derivative\DerivativeInterface.
*/
protected function getDerivativeFetcher($base_plugin_id, array $base_definition) {
protected function getDerivativeFetcher($base_plugin_id, $base_definition) {
if (!isset($this->derivativeFetchers[$base_plugin_id])) {
$this->derivativeFetchers[$base_plugin_id] = FALSE;
$class = $this->getDerivativeClass($base_definition);
......@@ -191,8 +191,7 @@ protected function getDerivativeFetcher($base_plugin_id, array $base_definition)
*/
protected function getDerivativeClass($base_definition) {
$class = NULL;
if (isset($base_definition['derivative'])) {
$class = $base_definition['derivative'];
if ((is_array($base_definition) || ($base_definition = (array) $base_definition)) && (isset($base_definition['derivative']) && $class = $base_definition['derivative'])) {
if (!is_subclass_of($class, '\Drupal\Component\Plugin\Derivative\DerivativeInterface')) {
throw new InvalidDerivativeClassException(sprintf('Plugin (%s) derivative class "%s" has to implement interface \Drupal\Component\Plugin\Derivative\DerivativeInterface', $base_definition['id'], $class));
}
......
......@@ -63,7 +63,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) {
public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
return $this->derivatives[$derivative_id];
}
......@@ -76,7 +76,7 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
// Also keep the 'entity' defined as is.
$this->derivatives[''] = $base_plugin_definition;
// Add definitions for each entity type and bundle.
......
......@@ -63,7 +63,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) {
public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
if (!isset($this->derivatives)) {
$this->getDerivativeDefinitions($base_plugin_definition);
}
......@@ -75,7 +75,7 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->fieldTypePluginManager->getDefinitions() as $plugin_id => $definition) {
$definition['definition_class'] = '\Drupal\Core\Field\TypedData\FieldItemDataDefinition';
$definition['list_definition_class'] = '\Drupal\Core\Field\FieldDefinition';
......
......@@ -14,7 +14,7 @@ class ContainerDerivativeDiscoveryDecorator extends DerivativeDiscoveryDecorator
/**
* {@inheritdoc}
*/
protected function getDerivativeFetcher($base_plugin_id, array $base_definition) {
protected function getDerivativeFetcher($base_plugin_id, $base_definition) {
if (!isset($this->derivativeFetchers[$base_plugin_id])) {
$this->derivativeFetchers[$base_plugin_id] = FALSE;
$class = $this->getDerivativeClass($base_definition);
......
......@@ -17,7 +17,7 @@ class CustomBlock extends DerivativeBase {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
$custom_blocks = entity_load_multiple('custom_block');
foreach ($custom_blocks as $custom_block) {
$this->derivatives[$custom_block->uuid()] = $base_plugin_definition;
......
......@@ -58,7 +58,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
$default_theme = $this->config->get('default');
foreach ($this->themeHandler->listInfo() as $theme_name => $theme) {
......
......@@ -47,7 +47,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
// Create contextual links for all mappers.
$mappers = $this->mapperManager->getMappers();
foreach ($mappers as $plugin_id => $mapper) {
......
......@@ -57,7 +57,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
$mappers = $this->mapperManager->getMappers();
foreach ($mappers as $plugin_id => $mapper) {
/** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
......
......@@ -49,7 +49,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
// Create contextual links for translatable entity types.
foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
$this->derivatives[$entity_type_id]['title'] = t('Translate');
......
......@@ -57,7 +57,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
// Create tabs for all possible entity types.
foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
// Find the route name for the translation overview.
......
......@@ -16,7 +16,7 @@ class SelectionBase extends DerivativeBase {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
$supported_entities = array(
'comment',
'file',
......
......@@ -70,7 +70,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = array();
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
......
......@@ -18,7 +18,7 @@ class LanguageBlock extends DerivativeBase {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
$language_manager = \Drupal::languageManager();
if ($language_manager instanceof ConfigurableLanguageManagerInterface) {
......
......@@ -52,7 +52,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* Implements DerivativeInterface::getDerivativeDefinition().
*/
public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) {
public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
if (!isset($this->derivatives)) {
$this->getDerivativeDefinitions($base_plugin_definition);
}
......@@ -64,7 +64,7 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin
/**
* Implements DerivativeInterface::getDerivativeDefinitions().
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
if (!isset($this->derivatives)) {
// Add in the default plugin configuration and the resource type.
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
......
......@@ -46,7 +46,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = array();
if ($default = $this->searchPageRepository->getDefaultSearchPage()) {
......
......@@ -48,7 +48,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->menuStorage->loadMultiple() as $menu => $entity) {
$this->derivatives[$menu] = $base_plugin_definition;
$this->derivatives[$menu]['admin_label'] = $entity->label();
......
......@@ -17,7 +17,7 @@ class ThemeLocalTask extends DerivativeBase {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
foreach (list_themes() as $theme_name => $theme) {
if ($theme->status) {
$this->derivatives[$theme_name] = $base_plugin_definition;
......
......@@ -17,7 +17,7 @@ class EntityTestLocalTasks extends DerivativeBase {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = array();
$types = entity_test_entity_types();
......
Supports Markdown
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