Browse Source

Add install hook to set new default settings

pull/731/head^2
Jared Whiklo 6 years ago
parent
commit
3bab76c8e9
  1. 25
      islandora.install
  2. 54
      islandora.module

25
islandora.install

@ -5,6 +5,8 @@
* Install/update hook implementations. * Install/update hook implementations.
*/ */
use Drupal\islandora\Form\IslandoraSettingsForm;
/** /**
* Implements hook_schema(). * Implements hook_schema().
*/ */
@ -52,3 +54,26 @@ function islandora_update_8001(&$sandbox) {
$action->delete(); $action->delete();
} }
} }
/**
* Add in default Gemini URI and Pseudo bundle setting values.
*/
function islandora_update_8002(&$sandbox) {
$config_factory = \Drupal::service('config.factory')->getEditable(IslandoraSettingsForm::CONFIG_NAME);
$changed = false;
$gemini_url = $config_factory->get(IslandoraSettingsForm::GEMINI_URL);
$pseudo_bundles = $config_factory->get(IslandoraSettingsForm::GEMINI_PSEUDO);
if (!isset($gemini_url)) {
$config_factory->set(IslandoraSettingsForm::GEMINI_URL, '');
$changed = true;
}
if (!isset($pseudo_bundles)) {
$config_factory->set(IslandoraSettingsForm::GEMINI_PSEUDO, []);
$changed = true;
}
if ($changed) {
$config_factory->save();
}
}

54
islandora.module

@ -379,31 +379,37 @@ function islandora_entity_extra_field_info() {
* Implements hook_entity_view(). * Implements hook_entity_view().
*/ */
function islandora_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { function islandora_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
$route_match_item = \Drupal::routeMatch()->getParameters()->all(); $config_factory = \Drupal::service('config.factory')->get(IslandoraSettingsForm::CONFIG_NAME);
// Get the parameter, which might be node, media or taxonomy term. $gemini_url = $config_factory->get(IslandoraSettingsForm::GEMINI_URL);
$current_entity = reset($route_match_item); $pseudo_fields = $config_factory->get(IslandoraSettingsForm::GEMINI_PSEUDO);
// Match exactly to ensure they are the same entity type too. // If we aren't configured then don't display.
if ($entity === $current_entity) { if (!empty($gemini_url) && count($pseudo_fields) > 0) {
if ($display->getComponent('field_gemini_uri')) { $route_match_item = \Drupal::routeMatch()->getParameters()->all();
$gemini = \Drupal::service('islandora.gemini.lookup'); // Get the parameter, which might be node, media or taxonomy term.
if ($gemini instanceof GeminiLookup) { $current_entity = reset($route_match_item);
$fedora_uri = $gemini->lookup($entity); // Match exactly to ensure they are the same entity type too.
if (!is_null($fedora_uri)) { if ($entity === $current_entity) {
$build['field_gemini_uri'] = [ if ($display->getComponent('field_gemini_uri')) {
'#type' => 'container', $gemini = \Drupal::service('islandora.gemini.lookup');
'#attributes' => [ if ($gemini instanceof GeminiLookup) {
'id' => 'field-gemini-uri', $fedora_uri = $gemini->lookup($entity);
], if (!is_null($fedora_uri)) {
'internal_label' => [ $build['field_gemini_uri'] = [
'#type' => 'item', '#type' => 'container',
'#title' => t('Fedora URI'), '#attributes' => [
'internal_uri' => [ 'id' => 'field-gemini-uri',
'#type' => 'link', ],
'#title' => t("@url", ['@url' => $fedora_uri]), 'internal_label' => [
'#url' => Url::fromUri($fedora_uri), '#type' => 'item',
'#title' => t('Fedora URI'),
'internal_uri' => [
'#type' => 'link',
'#title' => t("@url", ['@url' => $fedora_uri]),
'#url' => Url::fromUri($fedora_uri),
],
], ],
], ];
]; }
} }
} }
} }

Loading…
Cancel
Save