From 0f1a8bde39d93cafe01f5f95d6cd9fc5b2c94a48 Mon Sep 17 00:00:00 2001 From: dannylamb Date: Thu, 1 Jun 2017 16:21:24 -0300 Subject: [PATCH] =?UTF-8?q?Using=20hook=5Fmodules=5Finstalled=20instead=20?= =?UTF-8?q?of=20hook=5Finstall=20to=20force=20rest=20co=E2=80=A6=20(#64)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Using hook_modules_installed instead of hook_install to force rest config * brace facepalm * Having a hard time testing locally, so pushing to see what Travis thinks of this. * Not creating and just letting tests go without the rest config --- islandora.install | 18 ------------- islandora.module | 28 ++++++++++++++++++++- tests/src/Kernel/EventGeneratorTestBase.php | 2 +- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/islandora.install b/islandora.install index 351111df..e900f2f6 100644 --- a/islandora.install +++ b/islandora.install @@ -5,8 +5,6 @@ * Install/update hook implementations. */ -use Drupal\rest\Entity\RestResourceConfig; - /** * Implements hook_schema(). */ @@ -42,19 +40,3 @@ function islandora_schema() { ]; return $schema; } - -/** - * Implemets hook_install(). - */ -function islandora_install() { - $rest_config = RestResourceConfig::load('entity.node'); - - $configuration = [ - 'methods' => ['GET', 'POST', 'PATCH', 'DELETE'], - 'formats' => ['hal_json', 'jsonld'], - 'authentication' => ['basic_auth', 'jwt_auth', 'cookie'], - ]; - - $rest_config->set('configuration', $configuration); - $rest_config->save(TRUE); -} diff --git a/islandora.module b/islandora.module index e33cb44d..8d529c03 100644 --- a/islandora.module +++ b/islandora.module @@ -27,13 +27,39 @@ function islandora_help($route_name, RouteMatchInterface $route_match) { case 'help.page.islandora': $output = ''; $output .= '

' . t('About') . '

'; - $output .= '

' . t('This is a placeholder for future help text about Islandora.') . '

'; + $output .= '

' . t('Islandora integrates Drupal with a Fedora repository.') . '

'; return $output; default: } } +/** + * Implements hook_modules_installed(). + */ +function islandora_modules_installed($modules) { + // Ensure the auth and serialization formats we need are available. + if (in_array('rest', $modules)) { + $rest_resource_config_storage = \Drupal::service('entity_type.manager')->getStorage('rest_resource_config'); + $rest_resource_config = $rest_resource_config_storage->load('entity.node'); + + if ($rest_resource_config) { + $configuration = $rest_resource_config->get('configuration'); + + if (!in_array('jsonld', $configuration['formats'])) { + $configuration['formats'][] = 'jsonld'; + } + + if (!in_array('jwt_auth', $configuration['authentication'])) { + $configuration['authentication'][] = 'jwt_auth'; + } + + $rest_resource_config->set('configuration', $configuration); + $rest_resource_config->save(TRUE); + } + } +} + /** * Implements hook_rdf_namespaces(). */ diff --git a/tests/src/Kernel/EventGeneratorTestBase.php b/tests/src/Kernel/EventGeneratorTestBase.php index 810f91f4..f3ba664a 100644 --- a/tests/src/Kernel/EventGeneratorTestBase.php +++ b/tests/src/Kernel/EventGeneratorTestBase.php @@ -34,7 +34,7 @@ abstract class EventGeneratorTestBase extends IslandoraKernelTestBase { parent::setUp(); // Create a test user. - $this->user = $this->createUser(['add fedora resource entities']); + $this->user = $this->createUser(['administer nodes']); $test_type = NodeType::create([ 'type' => 'test_type',