Skip to content

Commit

Permalink
Merge pull request #24 from discoverygarden/AUCIR-138
Browse files Browse the repository at this point in the history
AUCIR-138: Add default media redirect
  • Loading branch information
nchiasson-dgi authored Feb 2, 2024
2 parents 62adb9a + 1c61785 commit 8fc51e3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This mapping lives in the configuration at `basic_ingest.settings.map`, and
contains a list of mapping objects supporting the following structure:

* `uri`: the URI of the model to apply this mapping to
* `media_type`: the ID of the media type this model should be mapped to
* `media_type`: the ID of the media type this model should be mapped to, use media to redirect to the generic media upload page
* `display_hints`: a sequence of display hint URIs applicable to the given
Media type, to narrow down the selection list.

Expand Down
4 changes: 2 additions & 2 deletions basic_ingest.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* General hook implementations.
*/

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\basic_ingest\Form\FieldModelToMedia;
use Drupal\basic_ingest\Form\NodeMediaRedirect;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
Expand Down
2 changes: 1 addition & 1 deletion config/install/basic_ingest.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ map:
- uri: 'https://schema.org/PublicationIssue'
media_type: null
- uri: 'http://purl.org/coar/resource_type/c_12ce'
media_type: video
media_type: media
79 changes: 45 additions & 34 deletions src/Form/FieldModelToMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Drupal\basic_ingest\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\taxonomy\TermStorageInterface;

/**
Expand Down Expand Up @@ -79,8 +79,7 @@ public static function setDisplayHints(array &$form, FormStateInterface $form_st
*/
protected static function getDisplayHints(FormStateInterface $form_state) {
$mapped = static::getMapped($form_state);
$hints = isset($mapped['display_hints']) ?
$mapped['display_hints'] :
$hints = $mapped['display_hints'] ??
[];

$term_storage = static::getTermStorage();
Expand Down Expand Up @@ -161,38 +160,50 @@ public static function submit(array &$form, FormStateInterface $form_state) {
$mapped = static::getMapped($form_state);

if (!empty($mapped['media_type'])) {
$query_params = [];

// Make the media be ingested in the context of the node, by default.
NestedArray::setValue(
$query_params,
static::NODE_COORDS,
$form_state->getFormObject()->getEntity()->id()
);

// Make the media ingest select the "original use" term, by default.
$original_use_id = static::getOriginalUseId();
if ($original_use_id) {
NestedArray::setValue(
$query_params,
static::USE_COORDS,
$original_use_id
);
}
switch ($mapped['media_type']) {
case 'media':
// If mapped to media, redirect to node's media upload page.
$form_state->setRedirect('islandora.add_media_to_node_page', [
'node' => $form_state->getFormObject()->getEntity()->id(),
]);
break;

default:
$query_params = [];

// Make the media be ingested in the
// context of the node, by default.
NestedArray::setValue(
$query_params,
static::NODE_COORDS,
$form_state->getFormObject()->getEntity()->id()
);

// Set the 'published' flag.
NestedArray::setValue(
$query_params,
static::PUBLISHED_FLAG,
$form_state->getValue('status', 1)
);

// Make the media ingest select the "original use" term, by default.
$original_use_id = static::getOriginalUseId();
if ($original_use_id) {
NestedArray::setValue(
$query_params,
static::USE_COORDS,
$original_use_id
);
}

// Actually set the redirect.
$form_state->setRedirect('entity.media.add_form', [
'media_type' => $mapped['media_type'],
], [
'query' => $query_params,
]);

// Set the 'published' flag.
NestedArray::setValue(
$query_params,
static::PUBLISHED_FLAG,
$form_state->getValue('status', 1)
);

// Actually set the redirect.
$form_state->setRedirect('entity.media.add_form', [
'media_type' => $mapped['media_type'],
], [
'query' => $query_params,
]);
}
}
}
}
Expand Down

0 comments on commit 8fc51e3

Please sign in to comment.