Browse Source

Using hook_modules_installed instead of hook_install to force rest co… (#64)

* 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
pull/756/head
dannylamb 7 years ago committed by Nick Ruest
parent
commit
0f1a8bde39
  1. 18
      islandora.install
  2. 28
      islandora.module
  3. 2
      tests/src/Kernel/EventGeneratorTestBase.php

18
islandora.install

@ -5,8 +5,6 @@
* Install/update hook implementations. * Install/update hook implementations.
*/ */
use Drupal\rest\Entity\RestResourceConfig;
/** /**
* Implements hook_schema(). * Implements hook_schema().
*/ */
@ -42,19 +40,3 @@ function islandora_schema() {
]; ];
return $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);
}

28
islandora.module

@ -27,13 +27,39 @@ function islandora_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.islandora': case 'help.page.islandora':
$output = ''; $output = '';
$output .= '<h3>' . t('About') . '</h3>'; $output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('This is a placeholder for future help text about Islandora.') . '</p>'; $output .= '<p>' . t('Islandora integrates Drupal with a Fedora repository.') . '</p>';
return $output; return $output;
default: 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(). * Implements hook_rdf_namespaces().
*/ */

2
tests/src/Kernel/EventGeneratorTestBase.php

@ -34,7 +34,7 @@ abstract class EventGeneratorTestBase extends IslandoraKernelTestBase {
parent::setUp(); parent::setUp();
// Create a test user. // Create a test user.
$this->user = $this->createUser(['add fedora resource entities']); $this->user = $this->createUser(['administer nodes']);
$test_type = NodeType::create([ $test_type = NodeType::create([
'type' => 'test_type', 'type' => 'test_type',

Loading…
Cancel
Save