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 19, 2023
1 parent 8c8de83 commit c1b4141
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
36 changes: 18 additions & 18 deletions modules/islandora_iiif/src/IiifInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ class IiifInfo {


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

/**
/**
* This module's config.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $iiifConfig;

/**
* JWT Auth provider service.
*
* @var \Drupal\jwt\Authentication\Provider\JwtAuth
*/
/**
* JWT Auth provider service.
*
* @var \Drupal\jwt\Authentication\Provider\JwtAuth
*/
protected $jwtAuth;

/**
Expand All @@ -52,34 +52,34 @@ class IiifInfo {
*/
protected $logger;


/**
* Constructs an IiifInfo object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Guzzle\Http\Client $http_client
* The HTTP Client.
* The HTTP Client.
* @param \Drupal\Core\Logger\LoggerChannelInterface $channel
* Logger channel.
* @param \Drupal\jwt\Authentication\Provider\JwtAuth $jwt_auth
* The JWT auth provider.
* The JWT auth provider.
*/
public function __construct(ConfigFactoryInterface $config_factory, Client $http_client, LoggerChannelInterface $channel, JwtAuth $jwt_auth) {
$this->configFactory = $config_factory;

$this->iiifConfig= $this->configFactory->get('islandora_iiif.settings');
$this->iiifConfig = $this->configFactory->get('islandora_iiif.settings');
$this->httpClient = $http_client;
$this->logger = $channel;
$this->jwtAuth = $jwt_auth;
}

/**
* The IIIF base URL for an image.
*
* Visiting this URL will resolve to the info.json for the image.
*
* @return string
* The absolute URL on the IIIF server.
* The absolute URL on the IIIF server.
*/
public function baseUrl($image) {

Expand All @@ -101,17 +101,18 @@ public function baseUrl($image) {
*
* @param \Drupal\File\FileInterface $file
* The image file.
* @return array|FALSE
*
* @return array|false
* The image dimensions in an array as [$width, $height]
*/
public function getImageDimensions(FileInterface $file) {
$iiif_url = $this->baseUrl($file);
try {
$info_json = $this->httpClient->request('get', $iiif_url, [
'headers' => [
'Authorization' => 'bearer ' . $this->jwtAuth->generateToken()
]
])->getBody();
'Authorization' => 'bearer ' . $this->jwtAuth->generateToken(),
],
])->getBody();
$resource = json_decode($info_json, TRUE);
$width = $resource['width'];
$height = $resource['height'];
Expand All @@ -125,5 +126,4 @@ public function getImageDimensions(FileInterface $file) {
return FALSE;
}


}
38 changes: 18 additions & 20 deletions modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,19 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Url;
use Drupal\iiif_presentation_api\Encoder\V3\IiifP;
use Drupal\islandora\IslandoraUtils;
use Drupal\islandora_iiif\IiiffInfo;
use Drupal\islandora_iiif\IiifInfo;
use Drupal\views\Plugin\views\style\StylePluginBase;
use Drupal\views\ResultRow;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\ServerException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\SerializerInterface;

/**
* Provide serializer format for IIIF Manifest.
Expand Down Expand Up @@ -74,7 +69,7 @@ class IIIFManifest extends StylePluginBase {
/**
* The IIIF Info service.
*
* @var IiifInfo
* @var \Drupal\islandora_iiif\IiifInfo
*/
protected $iiifInfo;

Expand Down Expand Up @@ -347,14 +342,16 @@ protected function getCanvasDimensions(string $iiif_url, FieldItemInterface $ima
if (isset($image->width) && is_numeric($image->width)
&& isset($image->height) && is_numeric($image->height)) {
return [intval($image->width),
intval($image->height)];
intval($image->height),
];
}

if ($properties = $image->getProperties()
&& isset($properties['width']) && is_numeric($properties['width'])
&& isset($properties['height']) && is_numeric($properties['width'])) {
return [intval($properties['width']),
intval($properties['height'])];
intval($properties['height']),
];
}

$entity = $image->entity;
Expand All @@ -363,8 +360,9 @@ protected function getCanvasDimensions(string $iiif_url, FieldItemInterface $ima
&& $entity->hasField('field_width')
&& !$entity->get('field_width')->isEmpty()
&& $entity->get('field_width')->value > 0) {
return [ $entity->get('field_width')->value,
$entity->get('field_height')->value];
return [$entity->get('field_width')->value,
$entity->get('field_height')->value,
];
}

if ($mime_type === 'image/tiff') {
Expand All @@ -376,7 +374,8 @@ protected function getCanvasDimensions(string $iiif_url, FieldItemInterface $ima
$image_size = getimagesize($path);
if ($image_size) {
return [intval($image_size[0]),
intval($image_size[1])];
intval($image_size[1]),
];
}
}
}
Expand All @@ -398,8 +397,8 @@ protected function getCanvasDimensions(string $iiif_url, FieldItemInterface $ima
* The entity at the current row.
* @param \Drupal\taxonomy\TermInterface|null $structured_text_term
* The term that structured text media references, if any.
*
* return String|FALSE
*
* return String|FALSE
* The absolute URL of the current row's structured text,
* or FALSE if none.
*/
Expand All @@ -412,7 +411,7 @@ protected function getOcrUrl(EntityInterface $entity, $structured_text_term) {
$ocr_field_name = $ocrField->definition['field_name'];
if (!is_null($ocr_field_name)) {
$ocrs = $ocr_entity->{$ocr_field_name};
$ocr = isset($ocrs[0]) ? $ocrs[0] : FALSE;
$ocr = $ocrs[0] ?? FALSE;
$ocr_url = $ocr->entity->createFileUrl(FALSE);
}
}
Expand Down Expand Up @@ -554,14 +553,13 @@ public function getFormats() {

/**
* Submit handler for options form.
*
* Used to store the structured text media term by URL instead of Ttid.
*
* @param array $form
* The form.
* The form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*
* @return void
* The form state object.
*/
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
$style_options = $form_state->getValue('style_options');
Expand Down

0 comments on commit c1b4141

Please sign in to comment.