Browse Source

Merge 6ae0cb035d into 3f7ca2ca10

pull/904/merge
Jason Hildebrand 2 years ago committed by GitHub
parent
commit
1f135d3059
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      modules/islandora_image/config/schema/islandora_image.schema.yml
  2. 26
      modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php
  3. 24
      modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php
  4. 22
      src/IslandoraUtils.php
  5. 15
      src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php

3
modules/islandora_image/config/schema/islandora_image.schema.yml

@ -23,6 +23,9 @@ action.configuration.generate_image_derivative:
args:
type: text
label: 'Convert Arguments'
inputargs:
type: text
label: 'Input arguments for convert'
scheme:
type: text
label: 'Flysystem scheme'

26
modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php

@ -23,7 +23,8 @@ class GenerateImageDerivative extends AbstractGenerateDerivative {
$config = parent::defaultConfiguration();
$config['mimetype'] = 'image/jpeg';
$config['path'] = '[date:custom:Y]-[date:custom:m]/[node:nid].jpg';
$config['destination_media_type'] = 'image';
$config['destination_media_type'] = 'image';
$config['inputargs'] = '';
return $config;
}
@ -33,7 +34,21 @@ class GenerateImageDerivative extends AbstractGenerateDerivative {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. image/jpeg, image/png, etc...)');
$form['args']['#description'] = $this->t('Additional command line arguments for ImageMagick convert (e.g. -resize 50%');
// adjust args title and description for better clarity
$form['args']['#title'] = $this->t('Additional output arguments');
$form['args']['#description'] = $this->t('Additional output options for ImageMagick convert (e.g. -resize 50% -unsharp 0x.5).<br>See <a target="_blank" href="https://imagemagick.org/script/convert.php">documentation</a> for available options.');
$new = [
'inputargs' => [
'#type' => 'textfield',
'#title' => $this->t('Additional input arguments'),
'#default_value' => $this->configuration['inputargs'],
'#rows' => '8',
'#description' => $this->t('Additional input options for ImageMagick convert (e.g. -density 144).<br>Check the <a target="_blank" href="https://manpages.ubuntu.com/manpages/trusty/man1/convert.im6.1.html">man page</a> to see which options are input options.'),
]
];
$form = $this->utils->array_insert_after($form, 'mimetype', $new);
return $form;
}
@ -53,4 +68,11 @@ class GenerateImageDerivative extends AbstractGenerateDerivative {
}
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['inputargs'] = $form_state->getValue('inputargs');
}
}

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

@ -26,6 +26,7 @@ class GenerateImageDerivativeFile extends AbstractGenerateDerivativeMediaFile {
$config['queue'] = 'islandora-connector-houdini';
$config['destination_media_type'] = 'file';
$config['scheme'] = $this->config->get('default_scheme');
$config['inputargs'] = '';
return $config;
}
@ -37,7 +38,30 @@ class GenerateImageDerivativeFile extends AbstractGenerateDerivativeMediaFile {
$form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. application/xml, etc...)');
$form['mimetype']['#value'] = 'image/jpeg';
$form['mimetype']['#type'] = 'hidden';
// adjust args title and description for better clarity
$form['args']['#title'] = $this->t('Additional output arguments');
$form['args']['#description'] = $this->t('Additional output options for ImageMagick convert (e.g. -resize 50% -unsharp 0x.5).<br>See <a target="_blank" href="https://imagemagick.org/script/convert.php">documentation</a> for available options.');
$new = [
'inputargs' => [
'#type' => 'textfield',
'#title' => $this->t('Additional input arguments'),
'#default_value' => $this->configuration['inputargs'],
'#rows' => '8',
'#description' => $this->t('Additional input options for ImageMagick convert (e.g. -density 144).<br>Check the <a target="_blank" href="https://manpages.ubuntu.com/manpages/trusty/man1/convert.im6.1.html">man page</a> to see which options are input options.'),
]
];
$form = $this->utils->array_insert_after($form, 'mimetype', $new);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['inputargs'] = $form_state->getValue('inputargs');
}
}

22
src/IslandoraUtils.php

@ -751,4 +751,26 @@ class IslandoraUtils {
return $parents;
}
/**
* Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended
* to the end of the array.
*
* This is not islandora specific, but a useful function that neither PHP nor Drupal provide.
* (is there still hope after 16 years? https://www.drupal.org/project/drupal/issues/66183 )
*
* @param array $array
* @param string $key
* @param array $new
*
* @return array
*
* Credit: https://gist.github.com/wpscholar/0deadce1bbfa4adb4e4c
*/
function array_insert_after( array $array, $key, array $new ) {
$keys = array_keys( $array );
$index = array_search( $key, $keys );
$pos = false === $index ? count( $array ) : $index + 1;
return array_merge( array_slice( $array, 0, $pos ), $new, array_slice( $array, $pos ) );
}
}

15
src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php

@ -27,6 +27,7 @@ class AbstractGenerateDerivativeMediaFile extends AbstractGenerateDerivativeBase
'event' => 'Generate Derivative',
'source_term_uri' => $uri,
'mimetype' => '',
'inputargs' => '',
'args' => '',
'path' => '[date:custom:Y]-[date:custom:m]/[media:mid].bin',
'source_field_name' => 'field_media_file',
@ -69,6 +70,7 @@ class AbstractGenerateDerivativeMediaFile extends AbstractGenerateDerivativeBase
$allowed = [
'queue',
'event',
'inputargs',
'args',
'source_uri',
'destination_uri',
@ -109,12 +111,20 @@ class AbstractGenerateDerivativeMediaFile extends AbstractGenerateDerivativeBase
'#description' => $this->t('File field on Media Type to hold derivative. Cannot be the same as source'),
];
$form['inputargs'] = [
'#type' => 'textfield',
'#title' => $this->t('Additional input arguments'),
'#default_value' => $this->configuration['inputargs'],
'#rows' => '8',
'#description' => $this->t('Additional command line options related to the source file'),
];
$form['args'] = [
'#type' => 'textfield',
'#title' => $this->t('Additional arguments'),
'#title' => $this->t('Additional output arguments'),
'#default_value' => $this->configuration['args'],
'#rows' => '8',
'#description' => $this->t('Additional command line arguments'),
'#description' => $this->t('Additional command line options related to the output file (derivative)'),
];
$form['mimetype'] = [
@ -170,6 +180,7 @@ class AbstractGenerateDerivativeMediaFile extends AbstractGenerateDerivativeBase
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['mimetype'] = $form_state->getValue('mimetype');
$this->configuration['inputargs'] = $form_state->getValue('inputargs');
$this->configuration['args'] = $form_state->getValue('args');
$this->configuration['scheme'] = $form_state->getValue('scheme');
$this->configuration['path'] = trim($form_state->getValue('path'), '\\/');

Loading…
Cancel
Save