Browse Source

phpcs fixes and using dependency injection

d9_islandora
Eli Zoller 4 years ago
parent
commit
1ed788a6e8
  1. 2
      islandora.routing.yml
  2. 36
      modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php
  3. 1
      modules/islandora_text_extraction/islandora_text_extraction.services.yml
  4. 66
      modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php
  5. 1
      tests/modules/integer_weight_test_views/test_views/views.view.test_integer_weight.yml
  6. 1
      tests/src/Functional/FormDisplayAlterReactionTest.php
  7. 1
      tests/src/Functional/GenerateDerivativeTestBase.php

2
islandora.routing.yml

@ -78,5 +78,3 @@ islandora.confirm_delete_media_and_file:
_form: 'Drupal\islandora\Form\ConfirmDeleteMediaAndFile'
requirements:
_permission: 'administer media+delete any media'

36
modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php

@ -2,16 +2,49 @@
namespace Drupal\islandora_iiif\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\UrlHelper;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ClientException;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form to configure IslandoraIIIF.
*/
class IslandoraIIIFConfigForm extends ConfigFormBase {
/**
* The HTTP client to fetch the files with.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* IslandoraIIIFConfigForm constructor.
*
* @param \GuzzleHttp\ClientInterface $http_client
* A Guzzle client object.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
*/
public function __construct(ClientInterface $http_client, ConfigFactoryInterface $config_factory) {
parent::__construct($config_factory);
$this->httpClient = $http_client;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('http_client'),
$container->get('config.factory'),
);
}
/**
* {@inheritdoc}
*/
@ -78,9 +111,8 @@ class IslandoraIIIFConfigForm extends ConfigFormBase {
* True if server returns 200 on a HEAD request.
*/
private function validateIiifUrl($server_uri) {
$client = \Drupal::httpClient();
try {
$result = $client->head($server_uri);
$result = $this->httpClient->head($server_uri);
return ($result->getStatusCode() == 200);
}
catch (ClientException $e) {

1
modules/islandora_text_extraction/islandora_text_extraction.services.yml

@ -5,4 +5,3 @@ services:
islandora_text_extraction.search_reindexer:
class: Drupal\islandora_text_extraction\SearchReindexer
arguments: ['@islandora.utils', '@logger.channel.islandora_text_extraction']

66
modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php

@ -2,11 +2,16 @@
namespace Drupal\islandora_text_extraction\Plugin\Field\FieldFormatter;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Entity\File;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\RendererInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Plugin implementation of the 'ocr_txt_formatter' formatter.
@ -17,7 +22,62 @@ use Drupal\file\Entity\File;
* field_types = {"file"}
* )
*/
class OcrTextFormatter extends FormatterBase {
class OcrTextFormatter extends FormatterBase implements ContainerFactoryPluginInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* OcrTextFormatter constructor.
*
* @param string $plugin_id
* The plugin_id for the formatter.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The definition of the field to which the formatter is associated.
* @param array $settings
* The formatter settings.
* @param string $label
* The formatter label display setting.
* @param string $view_mode
* The view mode.
* @param array $third_party_settings
* Third party settings.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, RendererInterface $renderer, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $renderer, $config_factory);
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$plugin_id,
$plugin_definition,
$configuration['field_definition'],
$configuration['settings'],
$configuration['label'],
$configuration['view_mode'],
$configuration['third_party_settings'],
$container->get('renderer'),
$container->get('config.factory'),
$container->get('entity_type.manager'),
);
}
/**
* {@inheritdoc}
@ -70,7 +130,7 @@ class OcrTextFormatter extends FormatterBase {
*/
protected function viewValue(FieldItemInterface $item) {
$fileItem = $item->getValue();
$file = File::load($fileItem['target_id']);
$file = $this->entityTypeManager->getStorage('file')->load($fileItem['target_id']);
$contents = file_get_contents($file->getFileUri());
if (mb_detect_encoding($contents) != 'UTF-8') {
$contents = utf8_encode($contents);

1
tests/modules/integer_weight_test_views/test_views/views.view.test_integer_weight.yml

@ -248,4 +248,3 @@ display:
- 'user.node_grants:view'
- user.permissions
tags: { }

1
tests/src/Functional/FormDisplayAlterReactionTest.php

@ -8,6 +8,7 @@ namespace Drupal\Tests\islandora\Functional;
* @group islandora
*/
class FormDisplayAlterReactionTest extends IslandoraFunctionalTestBase {
/**
* @covers \Drupal\islandora\Plugin\ContextReaction\FormDisplayAlterReaction::execute
* @covers \Drupal\islandora\Plugin\ContextReaction\FormDisplayAlterReaction::buildConfigurationForm

1
tests/src/Functional/GenerateDerivativeTestBase.php

@ -2,7 +2,6 @@
namespace Drupal\Tests\islandora\Functional;
/**
* Tests the GenerateDerivative action.
*/

Loading…
Cancel
Save