Browse Source

Merge branch '8.x-1.x'

main
dannylamb 4 years ago
parent
commit
19c2e51433
  1. 28
      islandora.install
  2. 10
      modules/islandora_text_extraction/islandora_text_extraction.module
  3. 4
      src/Plugin/Condition/EntityBundle.php
  4. 6
      tests/src/Functional/EntityBundleTest.php
  5. 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();
}

10
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';
}

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