Browse Source

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 <git@huntdesign.co.nz>
pull/773/head
dannylamb 5 years ago committed by GitHub
parent
commit
7b24912fd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      islandora.install
  2. 4
      src/Plugin/Condition/EntityBundle.php
  3. 6
      tests/src/Functional/EntityBundleTest.php
  4. 6
      tests/src/Functional/JsonldTypeAlterReactionTest.php

28
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();
}

4
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")),

6
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');

6
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.

Loading…
Cancel
Save