Browse Source

Improve wording on multi-file derivative Action forms.

pull/892/head
Rosie Le Faive 2 years ago
parent
commit
74dcfd0fa4
  1. 17
      modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php
  2. 3
      src/Controller/MediaSourceController.php
  3. 4
      src/MediaSource/MediaSourceService.php
  4. 25
      src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php

17
modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php

@ -6,7 +6,10 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\islandora\Plugin\Action\AbstractGenerateDerivativeMediaFile;
/**
* Emits a Node for generating derivatives event.
* Emits a Media for generating derivatives event.
*
* Attaches the result as a file in an image field on the emitting
* Media ("multi-file media").
*
* @Action(
* id = "generate_image_derivative_file",
@ -24,7 +27,6 @@ class GenerateImageDerivativeFile extends AbstractGenerateDerivativeMediaFile {
$config['path'] = '[date:custom:Y]-[date:custom:m]/[media:mid]-ImageService.jpg';
$config['mimetype'] = 'application/xml';
$config['queue'] = 'islandora-connector-houdini';
$config['destination_media_type'] = 'file';
$config['scheme'] = $this->config->get('default_scheme');
return $config;
}
@ -46,13 +48,18 @@ class GenerateImageDerivativeFile extends AbstractGenerateDerivativeMediaFile {
'#required' => TRUE,
'#type' => 'select',
'#options' => $file_options,
'#title' => $this->t('Destination Image field Name'),
'#title' => $this->t('Destination Image field'),
'#default_value' => $this->configuration['destination_field_name'],
'#description' => $this->t('Image field on Media to hold derivative. Cannot be the same as source'),
'#description' => $this->t('This Action stores the derivative in an
Image field. If you need to store the result in a File field, use
"Generate a Derivative File for Media Attachment". Selected target field
must be an additional field, not the media\'s main storage field.
Selected target field must be present on the media.'),
];
$form['mimetype']['#value'] = 'image/jpeg';
$form['mimetype']['#type'] = 'hidden';
$form['mimetype']['#description'] = 'Mimetype to convert to. Must be
compatible with the destination image field.';
return $form;
}

3
src/Controller/MediaSourceController.php

@ -280,8 +280,7 @@ class MediaSourceController extends ControllerBase {
*/
public function attachToMediaAccess(AccountInterface $account, RouteMatch $route_match) {
$media = $route_match->getParameter('media');
$node = $this->utils->getParentNode($media);
return AccessResult::allowedIf($node->access('update', $account) && $account->hasPermission('create media'));
return AccessResult::allowedIf($media->access('update', $account));
}
}

4
src/MediaSource/MediaSourceService.php

@ -268,8 +268,8 @@ class MediaSourceService {
'uri' => $content_location,
'filename' => $this->fileSystem->basename($content_location),
'filemime' => $mimetype,
'status' => FILE_STATUS_PERMANENT,
]);
$file->setPermanent();
// Validate file extension.
$source_field_config = $this->entityTypeManager->getStorage('field_config')->load("media.$bundle.$source_field");
@ -349,8 +349,8 @@ class MediaSourceService {
'uri' => $content_location,
'filename' => $this->fileSystem->basename($content_location),
'filemime' => $mimetype,
'status' => FILE_STATUS_PERMANENT,
]);
$file->setPermanent();
// Validate file extension.
$bundle = $media->bundle();

25
src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php

@ -7,7 +7,10 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Emits a Node for generating derivatives event.
* Emits a Media for generating derivatives event.
*
* Attaches the result as a file in a file field on the emitting
* Media ("multi-file media").
*
* @Action(
* id = "generate_derivative_file",
@ -88,19 +91,33 @@ class AbstractGenerateDerivativeMediaFile extends AbstractGenerateDerivativeBase
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$map = $this->entityFieldManager->getFieldMapByFieldType('file');
$file_fields = $map['media'];
$file_options = array_combine(array_keys($file_fields), array_keys($file_fields));
$file_options = array_merge(['' => ''], $file_options);
$map = $this->entityFieldManager->getFieldMapByFieldType('image');
$image_fields = $map['media'];
$image_options = array_combine(array_keys($image_fields), array_keys($image_fields));
$file_options = array_merge(['' => ''], $file_options, $image_options);
// @todo figure out how to write to thumbnail, which is not a real field.
// see https://github.com/Islandora/islandora/issues/891.
unset($file_options['thumbnail']);
$form['event']['#disabled'] = 'disabled';
$form['destination_field_name'] = [
'#required' => TRUE,
'#type' => 'select',
'#options' => $file_options,
'#title' => $this->t('Destination File field Name'),
'#title' => $this->t('Destination File field'),
'#default_value' => $this->configuration['destination_field_name'],
'#description' => $this->t('File field on Media Type to hold derivative. Cannot be the same as source'),
'#description' => $this->t('This Action stores a derivative file
in a File or Image field on a media. The destination field
must be an additional field, not the media\'s main storage field.
Selected destination field must be present on the media.'),
];
$form['args'] = [

Loading…
Cancel
Save