From 7b24912fd3cc5cd737235a910e9aae5814962c88 Mon Sep 17 00:00:00 2001 From: dannylamb Date: Mon, 13 Apr 2020 12:55:40 -0600 Subject: [PATCH] Renames `entity_bundle` to `islandora_entity_bundle` to avoid name collision (#772) * #1470 Move entity_bundle context plugin to islandora_entity_bundle to avoid ctools * Update hook * Update EntityBundleTest.php * Coding standards * Touching up tests * plugin.manager.condition, not plugin.manager.context... Co-authored-by: Jonathan Hunt --- islandora.install | 28 +++++++++++++++++++ src/Plugin/Condition/EntityBundle.php | 4 ++- tests/src/Functional/EntityBundleTest.php | 6 ++-- .../JsonldTypeAlterReactionTest.php | 6 ++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/islandora.install b/islandora.install index 526583d4..011ecb19 100644 --- a/islandora.install +++ b/islandora.install @@ -52,3 +52,31 @@ function islandora_update_8001(&$sandbox) { $action->delete(); } } + +/** + * Replaces 'entity_bundle' conditions with 'islandora_entity_bundle'. + * + * This prevents plugin naming collisions between islandora and ctools. + */ +function islandora_update_8002(&$sandbox) { + + // Find contexts that have the old 'entity_bundle' condition. + $results = \Drupal::entityQuery('context')->condition('conditions.entity_bundle.id', 'entity_bundle')->execute(); + + if (empty($results)) { + return; + } + + // Set each context config to use 'islandora_entity_bundle' instead. + foreach ($results as $result) { + $config = \Drupal::configFactory()->getEditable("context.context.$result"); + $condition = $config->get('conditions.entity_bundle'); + $condition['id'] = 'islandora_entity_bundle'; + $config->set('conditions.islandora_entity_bundle', $condition); + $config->clear('conditions.entity_bundle'); + $config->save(); + } + + // Force drupal to reload the config. + \Drupal::service('plugin.manager.condition')->clearCachedDefinitions(); +} diff --git a/src/Plugin/Condition/EntityBundle.php b/src/Plugin/Condition/EntityBundle.php index 4803fd49..bd42df54 100644 --- a/src/Plugin/Condition/EntityBundle.php +++ b/src/Plugin/Condition/EntityBundle.php @@ -8,8 +8,10 @@ use Drupal\Core\Form\FormStateInterface; /** * Provides a 'Entity Bundle' condition. * + * Namespaced to avoid conflict with ctools entity_bundle plugin. + * * @Condition( - * id = "entity_bundle", + * id = "islandora_entity_bundle", * label = @Translation("Entity Bundle"), * context_definitions = { * "node" = @ContextDefinition("entity:node", required = FALSE, label = @Translation("Node")), diff --git a/tests/src/Functional/EntityBundleTest.php b/tests/src/Functional/EntityBundleTest.php index 1ffc261e..740ce8c1 100644 --- a/tests/src/Functional/EntityBundleTest.php +++ b/tests/src/Functional/EntityBundleTest.php @@ -24,9 +24,9 @@ class EntityBundleTest extends IslandoraFunctionalTestBase { $this->drupalLogin($account); $this->createContext('Test', 'test'); - $this->addCondition('test', 'entity_bundle'); - $this->getSession()->getPage()->checkField("edit-conditions-entity-bundle-bundles-test-type"); - $this->getSession()->getPage()->findById("edit-conditions-entity-bundle-context-mapping-node")->selectOption("@node.node_route_context:node"); + $this->addCondition('test', 'islandora_entity_bundle'); + $this->getSession()->getPage()->checkField("edit-conditions-islandora-entity-bundle-bundles-test-type"); + $this->getSession()->getPage()->findById("edit-conditions-islandora-entity-bundle-context-mapping-node")->selectOption("@node.node_route_context:node"); $this->getSession()->getPage()->pressButton(t('Save and continue')); $this->addPresetReaction('test', 'index', 'hello_world'); diff --git a/tests/src/Functional/JsonldTypeAlterReactionTest.php b/tests/src/Functional/JsonldTypeAlterReactionTest.php index 0232518b..ce5aa081 100644 --- a/tests/src/Functional/JsonldTypeAlterReactionTest.php +++ b/tests/src/Functional/JsonldTypeAlterReactionTest.php @@ -70,9 +70,9 @@ class JsonldTypeAlterReactionTest extends JsonldSelfReferenceReactionTest { $this->assertSession() ->pageTextContains("The context $context_name has been saved"); - $this->addCondition('test', 'entity_bundle'); - $this->getSession()->getPage()->checkField("edit-conditions-entity-bundle-bundles-test-type"); - $this->getSession()->getPage()->findById("edit-conditions-entity-bundle-context-mapping-node")->selectOption("@node.node_route_context:node"); + $this->addCondition('test', 'islandora_entity_bundle'); + $this->getSession()->getPage()->checkField("edit-conditions-islandora-entity-bundle-bundles-test-type"); + $this->getSession()->getPage()->findById("edit-conditions-islandora-entity-bundle-context-mapping-node")->selectOption("@node.node_route_context:node"); $this->getSession()->getPage()->pressButton(t('Save and continue')); // The first time a Context is saved, you need to clear the cache.