|
|
@ -4,20 +4,15 @@ namespace Drupal\islandora_iiif\Plugin\Action; |
|
|
|
|
|
|
|
|
|
|
|
use Drupal\Component\Datetime\TimeInterface; |
|
|
|
use Drupal\Component\Datetime\TimeInterface; |
|
|
|
use Drupal\Core\Action\Plugin\Action\SaveAction; |
|
|
|
use Drupal\Core\Action\Plugin\Action\SaveAction; |
|
|
|
use Drupal\Core\Config\ImmutableConfig; |
|
|
|
|
|
|
|
use Drupal\Core\Entity\EntityInterface; |
|
|
|
|
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
|
|
use Drupal\file\FileInterface; |
|
|
|
|
|
|
|
use Drupal\Core\Logger\LoggerChannelInterface; |
|
|
|
use Drupal\Core\Logger\LoggerChannelInterface; |
|
|
|
use Drupal\Core\Session\AccountInterface; |
|
|
|
use Drupal\Core\Session\AccountInterface; |
|
|
|
use Drupal\islandora\IslandoraUtils; |
|
|
|
use Drupal\islandora\IslandoraUtils; |
|
|
|
use Drupal\islandora\MediaSource\MediaSourceService; |
|
|
|
use Drupal\islandora\MediaSource\MediaSourceService; |
|
|
|
use Drupal\islandora_iiif\IiifInfo; |
|
|
|
use Drupal\islandora_iiif\IiifInfo; |
|
|
|
use Drupal\media\MediaInterface; |
|
|
|
|
|
|
|
use Drupal\node\NodeInterface; |
|
|
|
|
|
|
|
use GuzzleHttp\Client; |
|
|
|
use GuzzleHttp\Client; |
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Provides an action that can save any entity. |
|
|
|
* Provides an action that can save any entity. |
|
|
|
* |
|
|
|
* |
|
|
@ -30,16 +25,16 @@ use Symfony\Component\HttpFoundation\Request; |
|
|
|
class MediaAttributesFromIiif extends SaveAction { |
|
|
|
class MediaAttributesFromIiif extends SaveAction { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The HTTP client |
|
|
|
* The HTTP client. |
|
|
|
* |
|
|
|
* |
|
|
|
* @var \GuzzleHttp\Client; |
|
|
|
* @var \GuzzleHttp\Client |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected $httpClient; |
|
|
|
protected $httpClient; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The IIIF Info service. |
|
|
|
* The IIIF Info service. |
|
|
|
* |
|
|
|
* |
|
|
|
* @var IiifInfo |
|
|
|
* @var \Drupal\islandora_iiif\IiifInfo |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected $iiifInfo; |
|
|
|
protected $iiifInfo; |
|
|
|
|
|
|
|
|
|
|
@ -76,14 +71,15 @@ protected $iiifInfo; |
|
|
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
|
|
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
|
|
|
* The entity type manager. |
|
|
|
* The entity type manager. |
|
|
|
* @param \Drupal\Component\Datetime\TimeInterface $time |
|
|
|
* @param \Drupal\Component\Datetime\TimeInterface $time |
|
|
|
* @param |
|
|
|
|
|
|
|
* The time service. |
|
|
|
* The time service. |
|
|
|
* @param \Guzzle\Http\Client $http_client |
|
|
|
* @param \Guzzle\Http\Client $http_client |
|
|
|
* The HTTP Client. |
|
|
|
* The HTTP Client. |
|
|
|
* @param IiifInfo $iiif_info |
|
|
|
* @param \Drupal\islandora_iiif\IiifInfo $iiif_info |
|
|
|
* The IIIF INfo service. |
|
|
|
* The IIIF INfo service. |
|
|
|
|
|
|
|
* @param \Drupal\islandora\IslandoraUtils $islandora_utils |
|
|
|
|
|
|
|
* Islandora utility functions. |
|
|
|
* @param \Drupal\islandora\MediaSource\MediaSourceService $media_source |
|
|
|
* @param \Drupal\islandora\MediaSource\MediaSourceService $media_source |
|
|
|
* Media source service. |
|
|
|
* Islandora media service. |
|
|
|
* @param \Drupal\Core\Logger\LoggerChannelInterface $channel |
|
|
|
* @param \Drupal\Core\Logger\LoggerChannelInterface $channel |
|
|
|
* Logger channel. |
|
|
|
* Logger channel. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -130,15 +126,16 @@ $this->logger = $channel; |
|
|
|
$original_file_mids = $this->utils->getMediaReferencingNodeAndTerm($entity, $original_file_term); |
|
|
|
$original_file_mids = $this->utils->getMediaReferencingNodeAndTerm($entity, $original_file_term); |
|
|
|
if (!empty($original_file_mids)) { |
|
|
|
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) { |
|
|
|
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); |
|
|
|
$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); |
|
|
|
$original_file = $this->mediaSource->getSourceFile($original_file_media); |
|
|
|
$mime_type = $original_file->getMimeType(); |
|
|
|
$mime_type = $original_file->getMimeType(); |
|
|
|
|
|
|
|
|
|
|
@ -146,7 +143,6 @@ $this->logger = $channel; |
|
|
|
[$width, $height] = $this->iiifInfo->getImageDimensions($original_file); |
|
|
|
[$width, $height] = $this->iiifInfo->getImageDimensions($original_file); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @todo Make field configurable. Low priority since this whole thing is a workaround for an Islandora limitation. |
|
|
|
// @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')) { |
|
|
|
if ($original_file_media->hasField('field_width') && $original_file_media->hasField('field_height')) { |
|
|
|
$original_file_media->set('field_height', $height); |
|
|
|
$original_file_media->set('field_height', $height); |
|
|
|