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/modules/islandora_text_extraction/islandora_text_extraction.module b/modules/islandora_text_extraction/islandora_text_extraction.module index 28a44553..a9440c90 100644 --- a/modules/islandora_text_extraction/islandora_text_extraction.module +++ b/modules/islandora_text_extraction/islandora_text_extraction.module @@ -34,11 +34,11 @@ function islandora_text_extraction_media_presave(MediaInterface $media) { return; } $text = $media->get('field_edited_text')->getValue(); - $file_id = $media->get('field_media_file')->getValue()[0]['target_id']; - $file = File::load($file_id); - $data = file_get_contents($file->getFileUri()); - $data = nl2br($data); - if ($text !== $data) { + if (!$text) { + $file_id = $media->get('field_media_file')->getValue()[0]['target_id']; + $file = File::load($file_id); + $data = file_get_contents($file->getFileUri()); + $data = nl2br($data); $media->set('field_edited_text', $data); $media->field_edited_text->format = 'basic_html'; } 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.