Browse Source

phpcs fixes for #1171

pull/836/head
Willow Gillingham 5 years ago
parent
commit
c975137614
  1. 19
      islandora.tokens.inc

19
islandora.tokens.inc

@ -7,10 +7,7 @@
* This file provides islandora tokens. * This file provides islandora tokens.
*/ */
use Drupal\media\Entity\Media;
use Drupal\file\Entity\File;
use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Render\BubbleableMetadata;
use Drupal\islandora\IslandoraUtils;
/** /**
* Implements hook_token_info(). * Implements hook_token_info().
@ -42,7 +39,6 @@ function islandora_token_info() {
'description' => t('Deprecated: Alternative text for Thumbnail Image associated with Islandora Object via Media.'), 'description' => t('Deprecated: Alternative text for Thumbnail Image associated with Islandora Object via Media.'),
]; ];
return [ return [
'types' => ['islandoratokens' => $type], 'types' => ['islandoratokens' => $type],
'tokens' => ['islandoratokens' => $node], 'tokens' => ['islandoratokens' => $node],
@ -57,9 +53,11 @@ function islandora_tokens($type, $tokens, array $data, array $options, Bubbleabl
if ($type == 'islandoratokens' && !empty($data['node'])) { if ($type == 'islandoratokens' && !empty($data['node'])) {
if (!is_array($tokens) || empty($tokens)) { if (!is_array($tokens) || empty($tokens)) {
\Drupal::logger('islandora') \Drupal::logger('islandora')
->alert('Tokens not correct format: @tokens', [ ->alert(
'@tokens' => print_r($tokens, 1), 'Tokens not correct format: @tokens', [
]); '@tokens' => print_r($tokens, 1),
]
);
return; return;
} }
$islandoraUtils = \Drupal::service('islandora.utils'); $islandoraUtils = \Drupal::service('islandora.utils');
@ -70,7 +68,7 @@ function islandora_tokens($type, $tokens, array $data, array $options, Bubbleabl
$term = $islandoraUtils->getTermForUri('http://pcdm.org/use#ThumbnailImage'); $term = $islandoraUtils->getTermForUri('http://pcdm.org/use#ThumbnailImage');
$media = $islandoraUtils->getMediaWithTerm($data['node'], $term); $media = $islandoraUtils->getMediaWithTerm($data['node'], $term);
// Is there media? // Is there media?
// @todo: is this single or multiple? // @todo is this single or multiple?
if ($media) { if ($media) {
$file = \Drupal::service('islandora.media_source_service')->getSourceFile($media); $file = \Drupal::service('islandora.media_source_service')->getSourceFile($media);
if (!empty($file)) { if (!empty($file)) {
@ -86,14 +84,15 @@ function islandora_tokens($type, $tokens, array $data, array $options, Bubbleabl
$term = $islandoraUtils->getTermForUri('http://pcdm.org/use#ThumbnailImage'); $term = $islandoraUtils->getTermForUri('http://pcdm.org/use#ThumbnailImage');
$media = $islandoraUtils->getMediaWithTerm($data['node'], $term); $media = $islandoraUtils->getMediaWithTerm($data['node'], $term);
// Is there media? // Is there media?
// @todo: is this single or multiple? // @todo is this single or multiple?
if ($media) { if ($media) {
// Is the media an image? // Is the media an image?
if (isset($media->field_media_image)) { if (isset($media->field_media_image)) {
$alt = $media->field_media_image[0]->alt; $alt = $media->field_media_image[0]->alt;
} }
} }
// @todo: get alt from original or service file, if thumbnail alt is empty. // @todo get alt from original or service file, if thumbnail
// alt is empty.
$replacements[$original] = $alt; $replacements[$original] = $alt;
break; break;
} }

Loading…
Cancel
Save