Browse Source

Islandora IIIF: Address PHPCS errors.

959-iiif-width-height-caching
Alexander O'Neill 1 year ago
parent
commit
8c8de83e9d
  1. 4
      modules/islandora_iiif/islandora_iiif.install
  2. 28
      modules/islandora_iiif/src/Plugin/Action/MediaAttributesFromIiif.php

4
modules/islandora_iiif/islandora_iiif.install

@ -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);
$data = Yaml::parseFile($config_path);
\Drupal::configFactory()->getEditable($config_id)->setData($data)->save(TRUE);
}

28
modules/islandora_iiif/src/Plugin/Action/MediaAttributesFromIiif.php

@ -4,20 +4,15 @@ namespace Drupal\islandora_iiif\Plugin\Action;
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.
*
@ -30,16 +25,16 @@ use Symfony\Component\HttpFoundation\Request;
class MediaAttributesFromIiif extends SaveAction {
/**
* The HTTP client
* The HTTP client.
*
* @var \GuzzleHttp\Client;
* @var \GuzzleHttp\Client
*/
protected $httpClient;
/**
* The IIIF Info service.
*
* @var IiifInfo
* @var \Drupal\islandora_iiif\IiifInfo
*/
protected $iiifInfo;
@ -76,14 +71,15 @@ protected $iiifInfo;
* @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
* @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.
*/
@ -130,15 +126,16 @@ $this->logger = $channel;
$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.
// 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
*/
$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();
@ -146,7 +143,6 @@ $this->logger = $channel;
[$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);

Loading…
Cancel
Save