Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Drupal Rector to Islandora. #943

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function islandora_advanced_search_theme() {
function islandora_advanced_search_library_info_alter(&$libraries, $extension) {
if ($extension == 'facets') {
// Override facets module javascript with customizations.
$path = '/' . drupal_get_path('module', 'islandora_advanced_search') . '/js/facets';
$path = '/' . \Drupal::service('extension.list.module')->getPath('islandora_advanced_search') . '/js/facets';
$libraries['soft-limit']['js'] = [
"$path/soft-limit.js" => [],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function testGenerateAudioDerivativeFromScratch() {
'field_media_of[0][target_id]' => 'Test Node',
'field_tags[0][target_id]' => 'Preservation Master',
];
$this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save'));
$this->drupalGet('media/add/' . $this->testMediaType->id());
$this->submitForm($values, $this->t('Save'));

$expected = [
'source_uri' => 'test_file.txt',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BreadcrumbsTest extends IslandoraFunctionalTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'islandora_breadcrumbs',
];

Expand Down Expand Up @@ -56,7 +56,7 @@ class BreadcrumbsTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

// Create some nodes.
Expand Down
34 changes: 2 additions & 32 deletions modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php
rosiel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Drupal\views\Plugin\views\style\StylePluginBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Url;
Expand Down Expand Up @@ -92,17 +91,10 @@ class IIIFManifest extends StylePluginBase {
*/
protected $messenger;

/**
* Module Handler for running hooks.
*
* @var \Drupal\Core\Extention\ModuleHandlerInterface
*/
protected $moduleHandler;

/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, SerializerInterface $serializer, Request $request, ImmutableConfig $iiif_config, EntityTypeManagerInterface $entity_type_manager, FileSystemInterface $file_system, Client $http_client, MessengerInterface $messenger, ModuleHandlerInterface $moduleHandler) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, SerializerInterface $serializer, Request $request, ImmutableConfig $iiif_config, EntityTypeManagerInterface $entity_type_manager, FileSystemInterface $file_system, Client $http_client, MessengerInterface $messenger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);

$this->serializer = $serializer;
Expand All @@ -112,7 +104,6 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
$this->fileSystem = $file_system;
$this->httpClient = $http_client;
$this->messenger = $messenger;
$this->moduleHandler = $moduleHandler;
}

/**
Expand All @@ -129,21 +120,10 @@ public static function create(ContainerInterface $container, array $configuratio
$container->get('entity_type.manager'),
$container->get('file_system'),
$container->get('http_client'),
$container->get('messenger'),
$container->get('module_handler')
$container->get('messenger')
);
}

/**
* Return the request property.
*
* @return \Symfony\Component\HttpFoundation\Request
* The Symfony request object
*/
public function getRequest() {
return $this->request;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -190,9 +170,6 @@ public function render() {

$content_type = 'json';

// Give other modules a chance to alter the manifest.
$this->moduleHandler->alter('islandora_iiif_manifest', $json, $this);

return $this->serializer->serialize($json, $content_type, ['views_style_plugin' => $this]);
}

Expand Down Expand Up @@ -311,13 +288,6 @@ protected function getTileSourceFromRow(ResultRow $row, $iiif_address, $iiif_bas
];
}

// Give other modules a chance to alter the canvas.
$alter_options = [
'options' => $this->options,
'views_plugin' => $this,
];
$this->moduleHandler->alter('islandora_iiif_manifest_canvas', $tmp_canvas, $row, $alter_options);

$canvases[] = $tmp_canvas;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public function testGenerateImageDerivativeFromScratch() {
'field_media_of[0][target_id]' => 'Test Node',
'field_tags[0][target_id]' => 'Preservation Master',
];
$this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save'));
$this->drupalGet('media/add/' . $this->testMediaType->id());
$this->submitForm($values, $this->t('Save'));

$expected = [
'source_uri' => 'test_file.txt',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function attachToMedia(
if (!$this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
throw new HttpException(500, "The destination directory does not exist, could not be created, or is not writable");
}
$file = file_save_data($contents, $content_location, FileSystemInterface::EXISTS_REPLACE);
$file = \Drupal::service('file.repository')->writeData($contents, $content_location, FileSystemInterface::EXISTS_REPLACE);
rosiel marked this conversation as resolved.
Show resolved Hide resolved
if ($media->hasField($destination_field)) {
$media->{$destination_field}->setValue([
'target_id' => $file->id(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LoadTest extends IslandoraFunctionalTestBase {
*
* @var array
*/
public static $modules = ['islandora_text_extraction'];
protected static $modules = ['islandora_text_extraction'];

/**
* A user with permission to administer site configuration.
Expand All @@ -29,7 +29,7 @@ class LoadTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();
$this->user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($this->user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function testGenerateVideoDerivativeFromScratch() {
'field_media_of[0][target_id]' => 'Test Node',
'field_tags[0][target_id]' => 'Preservation Master',
];
$this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save'));
$this->drupalGet('media/add/' . $this->testMediaType->id());
$this->submitForm($values, $this->t('Save'));

$expected = [
'source_uri' => 'test_file.txt',
Expand Down
6 changes: 3 additions & 3 deletions src/EventSubscriber/LinkHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\islandora\EventSubscriber;

use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
Expand All @@ -13,7 +14,6 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand Down Expand Up @@ -312,9 +312,9 @@ protected function generateRestLinks(EntityInterface $entity) {
/**
* Adds resource-specific link headers to appropriate responses.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* Event containing the response.
*/
abstract public function onResponse(FilterResponseEvent $event);
abstract public function onResponse(ResponseEvent $event);

}
4 changes: 2 additions & 2 deletions src/EventSubscriber/MediaLinkHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Drupal\islandora\EventSubscriber;

use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Drupal\Core\Url;
use Drupal\media\MediaInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;

/**
* Subscribes to MediaLinkHeader Event.
Expand All @@ -17,7 +17,7 @@ class MediaLinkHeaderSubscriber extends LinkHeaderSubscriber implements EventSub
/**
* {@inheritdoc}
*/
public function onResponse(FilterResponseEvent $event) {
public function onResponse(ResponseEvent $event) {
$response = $event->getResponse();

$media = $this->getObject($response, 'media');
Expand Down
6 changes: 3 additions & 3 deletions src/EventSubscriber/NodeLinkHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Drupal\islandora\EventSubscriber;

use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Drupal\node\NodeInterface;
use Drupal\islandora\IslandoraUtils;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
Expand All @@ -17,10 +17,10 @@ class NodeLinkHeaderSubscriber extends LinkHeaderSubscriber implements EventSubs
/**
* Adds node-specific link headers to appropriate responses.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* Event containing the response.
*/
public function onResponse(FilterResponseEvent $event) {
public function onResponse(ResponseEvent $event) {
$response = $event->getResponse();

$node = $this->getObject($response, 'node');
Expand Down
14 changes: 8 additions & 6 deletions src/Flysystem/Adapter/FedoraAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Drupal\islandora\Flysystem\Adapter;

use GuzzleHttp\Psr7\Header;
use function GuzzleHttp\Psr7\parse_header;
use Drupal\Core\Logger\LoggerChannelInterface;
use Islandora\Chullo\IFedoraApi;
use League\Flysystem\AdapterInterface;
Expand Down Expand Up @@ -159,11 +161,11 @@ protected function getMetadataFromHeaders(Response $response) {
// directory.
$type = 'dir';
// phpcs:disable
if (class_exists(\GuzzleHttp\Psr7\Header::class)) {
$links = \GuzzleHttp\Psr7\Header::parse($response->getHeader('Link'));
if (class_exists(Header::class)) {
$links = Header::parse($response->getHeader('Link'));
}
else {
$links = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link'));
$links = parse_header($response->getHeader('Link'));
}
// phpcs:enable
foreach ($links as $link) {
Expand Down Expand Up @@ -402,11 +404,11 @@ private function deleteTombstone($path) {
if ($response->getStatusCode() == 410) {
$return = FALSE;
// phpcs:disable
if (class_exists(\GuzzleHttp\Psr7\Header::class)) {
$link_headers = \GuzzleHttp\Psr7\Header::parse($response->getHeader('Link'));
if (class_exists(Header::class)) {
$link_headers = Header::parse($response->getHeader('Link'));
}
else {
$link_headers = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link'));
$link_headers = parse_header($response->getHeader('Link'));
}
// phpcs:enable
if ($link_headers) {
Expand Down
7 changes: 6 additions & 1 deletion src/Form/AddChildrenWizard/AbstractFileSelectionForm.php
rosiel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ abstract class AbstractFileSelectionForm extends FormBase {
* @var \Drupal\islandora\Form\AddChildrenWizard\AbstractBatchProcessor|null
*/
protected ?AbstractBatchProcessor $batchProcessor;
private \static $static;
public function __construct(\static $static)
{
$this->static = $static;
}

/**
* {@inheritdoc}
Expand All @@ -49,7 +54,7 @@ public static function create(ContainerInterface $container): self {
$instance->entityFieldManager = $container->get('entity_field.manager');
$instance->currentUser = $container->get('current_user');

$instance->batchProcessor = $container->get(static::BATCH_PROCESSOR);
$instance->batchProcessor = $this->static;

return $instance;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/AddChildTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AddChildTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

$this->parent =
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/AddMediaToNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AddMediaToNodeTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

$this->node = $this->container->get('entity_type.manager')->getStorage('node')->create([
Expand Down
3 changes: 2 additions & 1 deletion tests/src/Functional/ContentEntityTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public function testContentEntityType() {
'name[0][value]' => 'Test Media',
'files[field_media_file_0]' => __DIR__ . '/../../fixtures/test_file.txt',
];
$this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save'));
$this->drupalGet('media/add/' . $this->testMediaType->id());
$this->submitForm($values, $this->t('Save'));
$this->assertSession()->pageTextNotContains("Hello World!");
}

Expand Down
4 changes: 2 additions & 2 deletions tests/src/Functional/DeleteMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'media_test_views',
'context_ui',
'field_ui',
Expand Down Expand Up @@ -47,7 +47,7 @@ class DeleteMediaTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

// Create a test user.
Expand Down
5 changes: 3 additions & 2 deletions tests/src/Functional/DerivativeReactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DerivativeReactionTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

$this->node = $this->container->get('entity_type.manager')->getStorage('node')->create([
Expand Down Expand Up @@ -52,7 +52,8 @@ public function testExecuteDerivativeReaction() {
'files[field_media_file_0]' => __DIR__ . '/../../fixtures/test_file.txt',
'field_media_of[0][target_id]' => 'Test Node',
];
$this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save'));
$this->drupalGet('media/add/' . $this->testMediaType->id());
$this->submitForm($values, $this->t('Save'));

// field_media_of is set and there's a file, so derivatives should fire.
$this->assertSession()->pageTextContains("Hello World!");
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Functional/GenerateDerivativeTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class GenerateDerivativeTestBase extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

$this->createUserAndLogin();
Expand Down
5 changes: 3 additions & 2 deletions tests/src/Functional/IndexingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class IndexingTest extends IslandoraFunctionalTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
public function setUp(): void {
parent::setUp();

// Create an action that dsm's "Goodbye, Cruel World!".
Expand Down Expand Up @@ -63,9 +63,10 @@ public function testIndexing() {

// Add the Goodbye World reaction.
$this->addPresetReaction('test', 'delete', 'goodbye_world');
$this->drupalGet("$url/delete");

// Delete the node.
$this->drupalPostForm("$url/delete", [], $this->t('Delete'));
$this->submitForm([], $this->t('Delete'));
$this->assertSession()->statusCodeEquals(200);

// Confirm Goodbye, Cruel World! is printed to the screen.
Expand Down
Loading