Skip to content

Commit

Permalink
De-lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonhildebrand committed Sep 11, 2024
1 parent eb40ab0 commit 56f3440
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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).<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);
$form = $this->utils->arrayInsertAfter($form, 'mimetype', $new);
return $form;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).<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);
$form = $this->utils->arrayInsertAfter($form, 'mimetype', $new);

return $form;
}
Expand Down
47 changes: 26 additions & 21 deletions src/IslandoraUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 56f3440

Please sign in to comment.