From 3c969bf14f1775ebb6c52cc71b7558703f154210 Mon Sep 17 00:00:00 2001 From: dannylamb Date: Tue, 7 Apr 2020 07:36:45 -0600 Subject: [PATCH 1/2] Revert "update field_edited_text when different from the file contents (#769)" (#770) This reverts commit 163a621bc499d32a3b72da58b16b6a38d77694b4. --- .../islandora_text_extraction.module | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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'; } From 7b24912fd3cc5cd737235a910e9aae5814962c88 Mon Sep 17 00:00:00 2001 From: dannylamb Date: Mon, 13 Apr 2020 12:55:40 -0600 Subject: [PATCH 2/2] 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.