Skip to content

Commit

Permalink
Islandora IIIF: Address PHPCS errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
alxp committed Oct 18, 2023
1 parent 565a1b4 commit 8c8de83
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
8 changes: 5 additions & 3 deletions modules/islandora_iiif/islandora_iiif.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* Install/update hook implementations.
*/

/**
use Symfony\Component\Yaml\Yaml;

/**
* Add Media Attributes from IIIF action.
*/
function islandora_iiif_update_92001(&$sandbox) {
$config_id = 'system.action.media_attributes_from_iiif_action';
$config_path = \Drupal::service('extension.list.module')->getPath('islandora_iiif') . '/config/optional/' . $config_id .'.yml';
$data = \Symfony\Component\Yaml\Yaml::parseFile($config_path);
$config_path = \Drupal::service('extension.list.module')->getPath('islandora_iiif') . '/config/optional/' . $config_id . '.yml';
$data = Yaml::parseFile($config_path);
\Drupal::configFactory()->getEditable($config_id)->setData($data)->save(TRUE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Action\Plugin\Action\SaveAction;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\file\FileInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\islandora\IslandoraUtils;
use Drupal\islandora\MediaSource\MediaSourceService;
use Drupal\islandora_iiif\IiifInfo;
use Drupal\media\MediaInterface;
use Drupal\node\NodeInterface;
use GuzzleHttp\Client;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;

/**
* Provides an action that can save any entity.
*
Expand All @@ -30,18 +25,18 @@
class MediaAttributesFromIiif extends SaveAction {

/**
* The HTTP client
* The HTTP client.
*
* @var \GuzzleHttp\Client;
* @var \GuzzleHttp\Client
*/
protected $httpClient;

/**
* The IIIF Info service.
*
* @var IiifInfo
*/
protected $iiifInfo;
/**
* The IIIF Info service.
*
* @var \Drupal\islandora_iiif\IiifInfo
*/
protected $iiifInfo;

/**
* The logger.
Expand All @@ -50,7 +45,7 @@ class MediaAttributesFromIiif extends SaveAction {
*/
protected $logger;

/**
/**
* Islandora utility functions.
*
* @var \Drupal\islandora\IslandoraUtils
Expand All @@ -76,25 +71,26 @@ class MediaAttributesFromIiif extends SaveAction {
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Component\Datetime\TimeInterface $time
* @param
* The time service.
* @param \Guzzle\Http\Client $http_client
* The HTTP Client.
* @param IiifInfo $iiif_info
* The IIIF INfo service.
* The HTTP Client.
* @param \Drupal\islandora_iiif\IiifInfo $iiif_info
* The IIIF INfo service.
* @param \Drupal\islandora\IslandoraUtils $islandora_utils
* Islandora utility functions.
* @param \Drupal\islandora\MediaSource\MediaSourceService $media_source
* Media source service.
* Islandora media service.
* @param \Drupal\Core\Logger\LoggerChannelInterface $channel
* Logger channel.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, TimeInterface $time, Client $http_client, IiifInfo $iiif_info, IslandoraUtils $islandora_utils, MediaSourceService $media_source, LoggerChannelInterface $channel) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $time);

$this->httpClient = $http_client;
$this->iiifInfo = $iiif_info;
$this->utils = $islandora_utils;
$this->mediaSource = $media_source;
$this->logger = $channel;
$this->iiifInfo = $iiif_info;
$this->utils = $islandora_utils;
$this->mediaSource = $media_source;
$this->logger = $channel;
}

/**
Expand All @@ -118,7 +114,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function execute($entity = NULL ) {
public function execute($entity = NULL) {
$width = $height = FALSE;

// Get the original File media use term.
Expand All @@ -130,23 +126,23 @@ public function execute($entity = NULL ) {
$original_file_mids = $this->utils->getMediaReferencingNodeAndTerm($entity, $original_file_term);
if (!empty($original_file_mids)) {

// Ordinarily there shouldn't be more than one Original File media but it's not guaranteed.
foreach($original_file_mids as $original_file_mid) {
// Ordinarily there shouldn't be more than one Original File media but
// it's not guaranteed.
foreach ($original_file_mids as $original_file_mid) {

/*
* @var \Drupal\Media\MediaInterface $original_file_media
*/
/**
* @var \Drupal\Media\MediaInterface $original_file_media
*/
$original_file_media = $this->entityTypeManager->getStorage('media')->load($original_file_mid);

// Get the media MIME Type
// Get the media MIME Type.
$original_file = $this->mediaSource->getSourceFile($original_file_media);
$mime_type = $original_file->getMimeType();

if (in_array($mime_type, ['image/tiff', 'image/jp2'])) {
[$width, $height] = $this->iiifInfo->getImageDimensions($original_file);
}


// @todo Make field configurable. Low priority since this whole thing is a workaround for an Islandora limitation.
if ($original_file_media->hasField('field_width') && $original_file_media->hasField('field_height')) {
$original_file_media->set('field_height', $height);
Expand All @@ -166,4 +162,4 @@ public function access($object, AccountInterface $account = NULL, $return_as_obj
return $object->access('update', $account, $return_as_object);
}

}
}

0 comments on commit 8c8de83

Please sign in to comment.