Skip to content

Commit

Permalink
Add an "input args" parameter when defining derivative actions. In th…
Browse files Browse the repository at this point in the history
…e UI, this field is only exposed for image derivatives, where it allows passing "input options" to imagemagick convert (houdini).
  • Loading branch information
jasonhildebrand committed Oct 20, 2022
1 parent 0948436 commit 94bfdd0
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).<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['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.');
return $form;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).<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['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.');
return $form;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['mimetype']['#type'] = 'textfield';

unset($form['args']);
unset($form['inputargs']);
return $form;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions src/Plugin/Action/AbstractGenerateDerivative.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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'), '\\/');
Expand Down
15 changes: 13 additions & 2 deletions src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -69,6 +70,7 @@ protected function generateData(EntityInterface $entity) {
$allowed = [
'queue',
'event',
'inputargs',
'args',
'source_uri',
'destination_uri',
Expand Down Expand Up @@ -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'] = [
Expand Down Expand Up @@ -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'), '\\/');
Expand Down

0 comments on commit 94bfdd0

Please sign in to comment.