From 94bfdd0de17dfb2772fd25127e8e7f6723a2b52a Mon Sep 17 00:00:00 2001 From: Jason Hildebrand Date: Thu, 20 Oct 2022 16:11:14 -0500 Subject: [PATCH 1/5] Add an "input args" parameter when defining derivative actions. In the UI, this field is only exposed for image derivatives, where it allows passing "input options" to imagemagick convert (houdini). --- .../src/Plugin/Action/GenerateAudioDerivative.php | 1 + .../src/Plugin/Action/GenerateImageDerivative.php | 7 ++++++- .../Plugin/Action/GenerateImageDerivativeFile.php | 6 ++++++ .../src/Plugin/Action/GenerateOCRDerivative.php | 1 + .../Plugin/Action/GenerateOCRDerivativeFile.php | 1 + .../src/Plugin/Action/GenerateVideoDerivative.php | 1 + src/Plugin/Action/AbstractGenerateDerivative.php | 9 +++++++++ .../AbstractGenerateDerivativeMediaFile.php | 15 +++++++++++++-- 8 files changed, 38 insertions(+), 3 deletions(-) diff --git a/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php b/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php index 904d05e60..3f7ad8964 100644 --- a/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php +++ b/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php @@ -36,6 +36,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form = parent::buildConfigurationForm($form, $form_state); $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. audio/mpeg, audio/m4a, etc...)'); $form['args']['#description'] = $this->t('Additional command line parameters for FFMpeg'); + unset($form['inputargs']); return $form; } diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php index e81f157b1..758c73757 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php @@ -33,7 +33,12 @@ public function defaultConfiguration() { 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%'); + + $form['inputargs']['#title'] = $this->t('Additional input arguments'); + $form['inputargs']['#description'] = $this->t('Additional input options for ImageMagick convert (e.g. -density 144).
Check the man page to see which options are input options.'); + + $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).
See documentation for available options.'); return $form; } diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php index d6f99b584..8a9d73556 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php @@ -37,6 +37,12 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. application/xml, etc...)'); $form['mimetype']['#value'] = 'image/jpeg'; $form['mimetype']['#type'] = 'hidden'; + + $form['inputargs']['#title'] = $this->t('Additional input arguments'); + $form['inputargs']['#description'] = $this->t('Additional input options for ImageMagick convert (e.g. -density 144).
Check the man page to see which options are input options.'); + + $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).
See documentation for available options.'); return $form; } diff --git a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php index 745c57727..19417ec40 100644 --- a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php +++ b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php @@ -38,6 +38,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['mimetype']['#type'] = 'textfield'; unset($form['args']); + unset($form['inputargs']); return $form; } diff --git a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php index f6b8034a9..578f1b0c1 100644 --- a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php +++ b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php @@ -58,6 +58,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form = array_merge($first, $middle, $last); unset($form['args']); + unset($form['inputargs']); return $form; } diff --git a/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php b/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php index 7c8619923..d5fb710dc 100644 --- a/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php +++ b/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php @@ -35,6 +35,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form = parent::buildConfigurationForm($form, $form_state); $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. video/mp4, video/quicktime, etc...)'); $form['args']['#description'] = $this->t('Additional command line parameters for FFMpeg'); + unset($form['inputargs']); return $form; } diff --git a/src/Plugin/Action/AbstractGenerateDerivative.php b/src/Plugin/Action/AbstractGenerateDerivative.php index b22201e11..a2e44a65e 100644 --- a/src/Plugin/Action/AbstractGenerateDerivative.php +++ b/src/Plugin/Action/AbstractGenerateDerivative.php @@ -21,6 +21,7 @@ public function defaultConfiguration() { 'source_term_uri' => '', 'derivative_term_uri' => '', 'mimetype' => '', + 'inputargs' => '', 'args' => '', 'destination_media_type' => '', 'scheme' => $this->config->get('default_scheme'), @@ -130,6 +131,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#rows' => '8', '#description' => $this->t('Mimetype to convert to (e.g. image/jpeg, video/mp4, etc...)'), ]; + $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'), @@ -199,6 +207,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s $this->configuration['derivative_term_uri'] = $this->utils->getUriForTerm($term); $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'), '\\/'); diff --git a/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php b/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php index be9eca80b..157765919 100644 --- a/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php +++ b/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php @@ -27,6 +27,7 @@ public function defaultConfiguration() { '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 @@ protected function generateData(EntityInterface $entity) { $allowed = [ 'queue', 'event', + 'inputargs', 'args', 'source_uri', 'destination_uri', @@ -109,12 +111,20 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#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 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form 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'), '\\/'); From deff2ddb267f68c3f68f172dd39ed4c101442363 Mon Sep 17 00:00:00 2001 From: Jason Hildebrand Date: Mon, 24 Oct 2022 12:35:52 -0500 Subject: [PATCH 2/5] Implement inputargs in GenerateImageDerivative and GenerateImageDerivativeFile, instead of in AbstractGenerateDerivative. Add utility function to add a form element (or other array entry) at a specific position. --- .../Plugin/Action/GenerateAudioDerivative.php | 1 - .../config/schema/islandora_image.schema.yml | 3 +++ .../Plugin/Action/GenerateImageDerivative.php | 27 ++++++++++++++++--- .../Action/GenerateImageDerivativeFile.php | 24 ++++++++++++++--- .../Plugin/Action/GenerateOCRDerivative.php | 1 - .../Action/GenerateOCRDerivativeFile.php | 1 - .../Plugin/Action/GenerateVideoDerivative.php | 1 - src/IslandoraUtils.php | 22 +++++++++++++++ .../Action/AbstractGenerateDerivative.php | 9 ------- 9 files changed, 69 insertions(+), 20 deletions(-) diff --git a/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php b/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php index 3f7ad8964..904d05e60 100644 --- a/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php +++ b/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php @@ -36,7 +36,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form = parent::buildConfigurationForm($form, $form_state); $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. audio/mpeg, audio/m4a, etc...)'); $form['args']['#description'] = $this->t('Additional command line parameters for FFMpeg'); - unset($form['inputargs']); return $form; } diff --git a/modules/islandora_image/config/schema/islandora_image.schema.yml b/modules/islandora_image/config/schema/islandora_image.schema.yml index 687e7c110..e59108705 100644 --- a/modules/islandora_image/config/schema/islandora_image.schema.yml +++ b/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' diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php index 758c73757..8e49617ed 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php @@ -23,7 +23,8 @@ public function defaultConfiguration() { $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; } @@ -34,11 +35,22 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form = parent::buildConfigurationForm($form, $form_state); $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. image/jpeg, image/png, etc...)'); - $form['inputargs']['#title'] = $this->t('Additional input arguments'); - $form['inputargs']['#description'] = $this->t('Additional input options for ImageMagick convert (e.g. -density 144).
Check the man page to see which options are input options.'); - + // 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).
See documentation 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).
Check the man page to see which options are input options.'), + ] + ]; + $form = $this->utils->array_insert_after($form, 'mimetype', $new); + + return $form; } @@ -58,4 +70,11 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form } } + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + parent::submitConfigurationForm($form, $form_state); + $this->configuration['inputargs'] = $form_state->getValue('inputargs'); + } } diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php index 8a9d73556..dd7aa3734 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php @@ -26,6 +26,7 @@ public function defaultConfiguration() { $config['queue'] = 'islandora-connector-houdini'; $config['destination_media_type'] = 'file'; $config['scheme'] = $this->config->get('default_scheme'); + $config['inputargs'] = ''; return $config; } @@ -38,12 +39,29 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['mimetype']['#value'] = 'image/jpeg'; $form['mimetype']['#type'] = 'hidden'; - $form['inputargs']['#title'] = $this->t('Additional input arguments'); - $form['inputargs']['#description'] = $this->t('Additional input options for ImageMagick convert (e.g. -density 144).
Check the man page to see which options are input options.'); - + // 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).
See documentation 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).
Check the man page 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'); + } } diff --git a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php index 19417ec40..745c57727 100644 --- a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php +++ b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php @@ -38,7 +38,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['mimetype']['#type'] = 'textfield'; unset($form['args']); - unset($form['inputargs']); return $form; } diff --git a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php index 578f1b0c1..f6b8034a9 100644 --- a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php +++ b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php @@ -58,7 +58,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form = array_merge($first, $middle, $last); unset($form['args']); - unset($form['inputargs']); return $form; } diff --git a/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php b/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php index d5fb710dc..7c8619923 100644 --- a/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php +++ b/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php @@ -35,7 +35,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form = parent::buildConfigurationForm($form, $form_state); $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. video/mp4, video/quicktime, etc...)'); $form['args']['#description'] = $this->t('Additional command line parameters for FFMpeg'); - unset($form['inputargs']); return $form; } diff --git a/src/IslandoraUtils.php b/src/IslandoraUtils.php index f81cb7472..43f2fb78b 100644 --- a/src/IslandoraUtils.php +++ b/src/IslandoraUtils.php @@ -751,4 +751,26 @@ protected function getParentsByEntityReference(ContentEntityInterface $entity, a 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 ) ); + } + } diff --git a/src/Plugin/Action/AbstractGenerateDerivative.php b/src/Plugin/Action/AbstractGenerateDerivative.php index a2e44a65e..b22201e11 100644 --- a/src/Plugin/Action/AbstractGenerateDerivative.php +++ b/src/Plugin/Action/AbstractGenerateDerivative.php @@ -21,7 +21,6 @@ public function defaultConfiguration() { 'source_term_uri' => '', 'derivative_term_uri' => '', 'mimetype' => '', - 'inputargs' => '', 'args' => '', 'destination_media_type' => '', 'scheme' => $this->config->get('default_scheme'), @@ -131,13 +130,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#rows' => '8', '#description' => $this->t('Mimetype to convert to (e.g. image/jpeg, video/mp4, etc...)'), ]; - $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'), @@ -207,7 +199,6 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s $this->configuration['derivative_term_uri'] = $this->utils->getUriForTerm($term); $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'), '\\/'); From 6ae0cb035dc2ee49c56922cbd29358e8b2c98434 Mon Sep 17 00:00:00 2001 From: Jason Hildebrand Date: Mon, 24 Oct 2022 12:38:44 -0500 Subject: [PATCH 3/5] Removing extra whitespace. --- .../src/Plugin/Action/GenerateImageDerivative.php | 2 -- .../src/Plugin/Action/GenerateImageDerivativeFile.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php index 8e49617ed..dec556591 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php @@ -49,8 +49,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta ] ]; $form = $this->utils->array_insert_after($form, 'mimetype', $new); - - return $form; } diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php index dd7aa3734..a18f076e3 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php @@ -43,7 +43,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $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).
See documentation for available options.'); - $new = [ 'inputargs' => [ '#type' => 'textfield', @@ -54,6 +53,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta ] ]; $form = $this->utils->array_insert_after($form, 'mimetype', $new); + return $form; } From eb40ab0e94e8ea6e96ed9e54ffceccc4002ed233 Mon Sep 17 00:00:00 2001 From: Jason Hildebrand Date: Tue, 10 Sep 2024 18:00:44 -0500 Subject: [PATCH 4/5] De-lint. --- .../src/Plugin/Action/GenerateImageDerivative.php | 7 ++++--- .../src/Plugin/Action/GenerateImageDerivativeFile.php | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php index dec556591..4dee1c1e8 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php @@ -23,7 +23,7 @@ public function defaultConfiguration() { $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; } @@ -35,7 +35,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form = parent::buildConfigurationForm($form, $form_state); $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. image/jpeg, image/png, etc...)'); - // adjust args title and description for better clarity + // 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).
See documentation for available options.'); @@ -46,7 +46,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#default_value' => $this->configuration['inputargs'], '#rows' => '8', '#description' => $this->t('Additional input options for ImageMagick convert (e.g. -density 144).
Check the man page to see which options are input options.'), - ] + ], ]; $form = $this->utils->array_insert_after($form, 'mimetype', $new); return $form; @@ -75,4 +75,5 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s parent::submitConfigurationForm($form, $form_state); $this->configuration['inputargs'] = $form_state->getValue('inputargs'); } + } diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php index e5784f70d..d2c1e8ccc 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php @@ -63,7 +63,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta compatible with the destination image field.'; $form['mimetype']['#type'] = 'hidden'; - // adjust args title and description for better clarity + // 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).
See documentation for available options.'); @@ -74,9 +74,10 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#default_value' => $this->configuration['inputargs'], '#rows' => '8', '#description' => $this->t('Additional input options for ImageMagick convert (e.g. -density 144).
Check the man page to see which options are input options.'), - ] + ], ]; $form = $this->utils->array_insert_after($form, 'mimetype', $new); + return $form; } @@ -87,4 +88,5 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s parent::submitConfigurationForm($form, $form_state); $this->configuration['inputargs'] = $form_state->getValue('inputargs'); } + } From 56f34409f4b328fda7a9785e9e4c508398837e79 Mon Sep 17 00:00:00 2001 From: Jason Hildebrand Date: Wed, 11 Sep 2024 09:27:49 -0500 Subject: [PATCH 5/5] De-lint. --- .../Plugin/Action/GenerateImageDerivative.php | 2 +- .../Action/GenerateImageDerivativeFile.php | 2 +- src/IslandoraUtils.php | 47 ++++++++++--------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php index 4dee1c1e8..42ee9a295 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php @@ -48,7 +48,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#description' => $this->t('Additional input options for ImageMagick convert (e.g. -density 144).
Check the man page to see which options are input options.'), ], ]; - $form = $this->utils->array_insert_after($form, 'mimetype', $new); + $form = $this->utils->arrayInsertAfter($form, 'mimetype', $new); return $form; } diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php index d2c1e8ccc..1529623ee 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php @@ -76,7 +76,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#description' => $this->t('Additional input options for ImageMagick convert (e.g. -density 144).
Check the man page to see which options are input options.'), ], ]; - $form = $this->utils->array_insert_after($form, 'mimetype', $new); + $form = $this->utils->arrayInsertAfter($form, 'mimetype', $new); return $form; } diff --git a/src/IslandoraUtils.php b/src/IslandoraUtils.php index bf80aa24e..78fcd57dd 100644 --- a/src/IslandoraUtils.php +++ b/src/IslandoraUtils.php @@ -103,7 +103,7 @@ public function __construct( ContextManager $context_manager, FlysystemFactory $flysystem_factory, LanguageManagerInterface $language_manager, - AccountInterface $current_user + AccountInterface $current_user, ) { $this->entityTypeManager = $entity_type_manager; $this->entityFieldManager = $entity_field_manager; @@ -769,27 +769,32 @@ protected function getParentsByEntityReference(ContentEntityInterface $entity, a } /** - * 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 ) ); + * 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 ) + * + * Credit: https://gist.github.com/wpscholar/0deadce1bbfa4adb4e4c + * + * @param array $array + * Array in which the new element should be inserted. + * @param string $key + * The key after which the new element should be inserted. + * @param array $new + * The new element to insert. + * + * @return array + * The new array. + */ + public function arrayInsertAfter(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)); } - + /** * Deletes Media and all associated files. *