From 761431604df7cb3571f27a84b972a56c20a6e577 Mon Sep 17 00:00:00 2001 From: Adam Nagy Date: Mon, 13 Jan 2025 12:33:58 +0100 Subject: [PATCH] EWPP-4991: Ensure PHP8.3 compatibility. --- .drone.yml | 32 ++++++++--------- composer.json | 13 +++++-- docker-compose.yml | 7 ++-- grumphp.yml.dist | 36 ++++--------------- .../CallProposalsDeadlineDateValidator.php | 2 +- .../Kernel/CallForProposalsKernelTestBase.php | 4 +-- .../Kernel/CallForTendersKernelTestBase.php | 4 +-- .../src/Kernel/ConsultationKernelTestBase.php | 2 +- .../oe_content_entity.module | 1 + .../src/Kernel/EventSpeakerEntityTest.php | 2 +- .../EventFieldsRequiredValidator.php | 2 +- .../tests/src/Kernel/EventKernelTestBase.php | 2 +- .../FeaturedMediaEntityBrowserWidget.php | 3 +- .../src/Kernel/OrganisationFieldTest.php | 2 +- .../src/Plugin/Filter/FilterPurl.php | 19 ++++++++-- .../Linkit/Matcher/MediaPurlMatcher.php | 2 +- .../tests/src/Kernel/PersonEntityTestBase.php | 2 +- .../tests/src/Kernel/PersonJobEntityTest.php | 2 +- .../PublicationFieldsRequiredValidator.php | 2 +- .../src/Kernel/PublicationEntityTest.php | 4 +-- .../src/Kernel/AuthorSkosUpdaterTest.php | 2 +- phpstan.neon.dist | 6 ++++ src/CallEntityWrapperBase.php | 21 +++++++++++ src/Form/EntityTypeForm.php | 2 ++ .../Behat/Hook/Call/EntityAwareHookBase.php | 1 + tests/src/Kernel/BaseFieldsTest.php | 2 +- .../src/Kernel/ShortTitleTokenReplaceTest.php | 2 +- tests/src/Traits/EntityLoadingTrait.php | 6 ++-- .../Traits/EntityReferenceRevisionTrait.php | 2 ++ tests/src/Traits/EntityReferenceTrait.php | 2 ++ 30 files changed, 111 insertions(+), 78 deletions(-) create mode 100644 phpstan.neon.dist diff --git a/.drone.yml b/.drone.yml index 7dedb6fc8..23786e7d0 100644 --- a/.drone.yml +++ b/.drone.yml @@ -19,8 +19,8 @@ services: - COMPOSERVER=--2 - DOCUMENT_ROOT=/test/oe_content mysql: - image: git.fpfis.tech.ec.europa.eu/fpfis/dependency_proxy/containers/percona:5.7 - command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3 + image: git.fpfis.tech.ec.europa.eu/fpfis/dependency_proxy/containers/percona:8.0 + command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3 --skip-log-bin --innodb-flush-log-at-trx-commit=2 --innodb-read-io-threads=16 --innodb-write-io-threads=16 environment: - MYSQL_ALLOW_EMPTY_PASSWORD=yes sparql: @@ -103,22 +103,22 @@ pipeline: matrix: include: - - { PHP_VERSION: 8.1, CORE_VERSION: 10.2.0, TYPE: phpunit } - - { PHP_VERSION: 8.1, CORE_VERSION: 10.2.0, TYPE: behat, BATCH: '@batch1' } - - { PHP_VERSION: 8.1, CORE_VERSION: 10.2.0, TYPE: behat, BATCH: '@batch2' } - - { PHP_VERSION: 8.1, CORE_VERSION: 10.2.0, TYPE: behat, BATCH: '@batch3' } - - - { PHP_VERSION: 8.2, CORE_VERSION: 10.2.0, TYPE: phpunit } - - { PHP_VERSION: 8.2, CORE_VERSION: 10.2.0, TYPE: behat, BATCH: '@batch1' } - - { PHP_VERSION: 8.2, CORE_VERSION: 10.2.0, TYPE: behat, BATCH: '@batch2' } - - { PHP_VERSION: 8.2, CORE_VERSION: 10.2.0, TYPE: behat, BATCH: '@batch3' } - - { PHP_VERSION: 8.1, CORE_VERSION: 10.3.0, TYPE: phpunit } - { PHP_VERSION: 8.1, CORE_VERSION: 10.3.0, TYPE: behat, BATCH: '@batch1' } - { PHP_VERSION: 8.1, CORE_VERSION: 10.3.0, TYPE: behat, BATCH: '@batch2' } - { PHP_VERSION: 8.1, CORE_VERSION: 10.3.0, TYPE: behat, BATCH: '@batch3' } - - { PHP_VERSION: 8.2, CORE_VERSION: 10.3.0, TYPE: phpunit } - - { PHP_VERSION: 8.2, CORE_VERSION: 10.3.0, TYPE: behat, BATCH: '@batch1' } - - { PHP_VERSION: 8.2, CORE_VERSION: 10.3.0, TYPE: behat, BATCH: '@batch2' } - - { PHP_VERSION: 8.2, CORE_VERSION: 10.3.0, TYPE: behat, BATCH: '@batch3' } + - { PHP_VERSION: 8.3, CORE_VERSION: 10.3.0, TYPE: phpunit } + - { PHP_VERSION: 8.3, CORE_VERSION: 10.3.0, TYPE: behat, BATCH: '@batch1' } + - { PHP_VERSION: 8.3, CORE_VERSION: 10.3.0, TYPE: behat, BATCH: '@batch2' } + - { PHP_VERSION: 8.3, CORE_VERSION: 10.3.0, TYPE: behat, BATCH: '@batch3' } + + - { PHP_VERSION: 8.1, CORE_VERSION: 10.4.0, TYPE: phpunit } + - { PHP_VERSION: 8.1, CORE_VERSION: 10.4.0, TYPE: behat, BATCH: '@batch1' } + - { PHP_VERSION: 8.1, CORE_VERSION: 10.4.0, TYPE: behat, BATCH: '@batch2' } + - { PHP_VERSION: 8.1, CORE_VERSION: 10.4.0, TYPE: behat, BATCH: '@batch3' } + + - { PHP_VERSION: 8.3, CORE_VERSION: 10.4.0, TYPE: phpunit } + - { PHP_VERSION: 8.3, CORE_VERSION: 10.4.0, TYPE: behat, BATCH: '@batch1' } + - { PHP_VERSION: 8.3, CORE_VERSION: 10.4.0, TYPE: behat, BATCH: '@batch2' } + - { PHP_VERSION: 8.3, CORE_VERSION: 10.4.0, TYPE: behat, BATCH: '@batch3' } diff --git a/composer.json b/composer.json index d8d5a4bcb..3703260d9 100644 --- a/composer.json +++ b/composer.json @@ -36,13 +36,13 @@ "mikey179/vfsstream": "^1.6", "nikic/php-parser": "^4.18", "openeuropa/behat-transformation-context": "~0.2", - "openeuropa/code-review": "^2.0", + "openeuropa/code-review-drupal": "^1.0.0-alpha", "openeuropa/oe_corporate_countries": "^2.0.0-alpha6", "openeuropa/oe_corporate_site_info": "^1.0", "openeuropa/oe_link_lists": "~0.21", "openeuropa/oe_multilingual": "^1.18", "openeuropa/oe_time_caching": "^1.5", - "openeuropa/task-runner-drupal-project-symlink": "^1.0.0-beta6", + "openeuropa/task-runner-drupal-project-symlink": "^1.0", "openeuropa/task-runner-ensure-behat-batching": "^1.0", "phpspec/prophecy-phpunit": "^2", "symfony/phpunit-bridge": "^6.0" @@ -70,6 +70,14 @@ { "type": "composer", "url": "https://packages.drupal.org/8" + }, + { + "type": "git", + "url": "https://github.com/openeuropa/DrupalDriver.git" + }, + { + "type": "git", + "url": "https://github.com/openeuropa/code-review-drupal.git" } ], "extra": { @@ -112,6 +120,7 @@ "drupal/core-composer-scaffold": true, "enable-patching": true, "phpro/grumphp": true, + "phpro/grumphp-shim": true, "phpstan/extension-installer": true } } diff --git a/docker-compose.yml b/docker-compose.yml index 4b1768e18..e66e21b72 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,6 @@ -version: '2' services: web: - image: fpfis/httpd-php-dev:8.2 + image: fpfis/httpd-php-dev:8.3 working_dir: /var/www/html ports: - 8080:8080 @@ -17,8 +16,8 @@ services: # Enable step debugging for all PHP request. See ./README.md#step-debugging for more information. #XDEBUG_SESSION: 1 mysql: - image: percona/percona-server:5.7 - command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3 + image: percona/percona-server:8.0 + command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3 --skip-log-bin --innodb-flush-log-at-trx-commit=2 --innodb-read-io-threads=16 --innodb-write-io-threads=16 environment: MYSQL_ALLOW_EMPTY_PASSWORD: "yes" # ports: diff --git a/grumphp.yml.dist b/grumphp.yml.dist index 8b66783e1..af65fba54 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -1,36 +1,12 @@ imports: - - { resource: vendor/openeuropa/code-review/dist/drupal-conventions.yml } - + - { resource: ./vendor/openeuropa/code-review-drupal/dist/oe-component-conventions.yml } grumphp: + tasks: + phpparser: + ignore_patterns: + - vendor/ git_hook_variables: EXEC_GRUMPHP_COMMAND: 'docker-compose exec -T web' - extensions: - - OpenEuropa\CodeReview\ExtraTasksExtension parameters: - tasks.phpcs.ignore_patterns: - - build/ - - node_modules/ - - vendor/ - tasks.phpcs.triggered_by: - - php - - module - - inc - - theme - - install - - yml - - extra_tasks: - phpparser: - ignore_patterns: - - build/ - - node_modules/ - - vendor/ - visitors: - declare_strict_types: ~ - triggered_by: - - php - - module - - inc - - theme - - install + tasks.phpstan.configuration: phpstan.neon.dist diff --git a/modules/oe_content_call_proposals/src/Plugin/Validation/Constraint/CallProposalsDeadlineDateValidator.php b/modules/oe_content_call_proposals/src/Plugin/Validation/Constraint/CallProposalsDeadlineDateValidator.php index 5194c5256..1f8c747bf 100644 --- a/modules/oe_content_call_proposals/src/Plugin/Validation/Constraint/CallProposalsDeadlineDateValidator.php +++ b/modules/oe_content_call_proposals/src/Plugin/Validation/Constraint/CallProposalsDeadlineDateValidator.php @@ -18,11 +18,11 @@ class CallProposalsDeadlineDateValidator extends ConstraintValidator { * {@inheritdoc} */ public function validate($node, Constraint $constraint) { - /** @var \Drupal\node\NodeInterface $node */ if (!isset($node) || $node->getType() !== 'oe_call_proposals') { return; } + /** @var \Drupal\node\NodeInterface $node */ $wrapper = CallForProposalsNodeWrapper::getInstance($node); $deadline_model = $wrapper->getModel(); diff --git a/modules/oe_content_call_proposals/tests/src/Kernel/CallForProposalsKernelTestBase.php b/modules/oe_content_call_proposals/tests/src/Kernel/CallForProposalsKernelTestBase.php index 8d0473ec8..13a0e1b54 100644 --- a/modules/oe_content_call_proposals/tests/src/Kernel/CallForProposalsKernelTestBase.php +++ b/modules/oe_content_call_proposals/tests/src/Kernel/CallForProposalsKernelTestBase.php @@ -58,7 +58,7 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installEntitySchema('media'); $this->installEntitySchema('entity_test'); - module_load_include('install', 'oe_content_documents_field'); + $this->container->get('module_handler')->loadInclude('oe_content_documents_field', 'install'); oe_content_documents_field_install(FALSE); $this->installConfig([ 'field', @@ -69,7 +69,7 @@ protected function setUp(): void { 'oe_content_social_media_links_field', 'oe_content_call_proposals', ]); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); } diff --git a/modules/oe_content_call_tenders/tests/src/Kernel/CallForTendersKernelTestBase.php b/modules/oe_content_call_tenders/tests/src/Kernel/CallForTendersKernelTestBase.php index 029cc37c5..baef0c648 100644 --- a/modules/oe_content_call_tenders/tests/src/Kernel/CallForTendersKernelTestBase.php +++ b/modules/oe_content_call_tenders/tests/src/Kernel/CallForTendersKernelTestBase.php @@ -56,7 +56,7 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installEntitySchema('media'); $this->installEntitySchema('entity_test'); - module_load_include('install', 'oe_content_documents_field'); + $this->container->get('module_handler')->loadInclude('oe_content_documents_field', 'install'); oe_content_documents_field_install(FALSE); $this->installConfig([ 'field', @@ -67,7 +67,7 @@ protected function setUp(): void { 'oe_content_social_media_links_field', 'oe_content_call_tenders', ]); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); } diff --git a/modules/oe_content_consultation/tests/src/Kernel/ConsultationKernelTestBase.php b/modules/oe_content_consultation/tests/src/Kernel/ConsultationKernelTestBase.php index a1930e7f8..52bb1a470 100644 --- a/modules/oe_content_consultation/tests/src/Kernel/ConsultationKernelTestBase.php +++ b/modules/oe_content_consultation/tests/src/Kernel/ConsultationKernelTestBase.php @@ -62,7 +62,7 @@ protected function setUp(): void { 'oe_content_departments_field', 'oe_content_consultation', ]); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); } diff --git a/modules/oe_content_entity/oe_content_entity.module b/modules/oe_content_entity/oe_content_entity.module index b224ac560..44619cbf9 100644 --- a/modules/oe_content_entity/oe_content_entity.module +++ b/modules/oe_content_entity/oe_content_entity.module @@ -46,6 +46,7 @@ function oe_content_entity_default_preprocess(array &$variables, string $hook): function oe_content_entity_default_theme_suggestion(array &$variables, string $hook): array { // We assume that the entity name and the theme hook are the same. $entity_key = '#' . $hook; + $entity = NULL; if (isset($variables['elements'][$entity_key])) { $entity = $variables['elements'][$entity_key]; } diff --git a/modules/oe_content_event/modules/oe_content_event_person_reference/tests/src/Kernel/EventSpeakerEntityTest.php b/modules/oe_content_event/modules/oe_content_event_person_reference/tests/src/Kernel/EventSpeakerEntityTest.php index c12c98597..f5aa28064 100644 --- a/modules/oe_content_event/modules/oe_content_event_person_reference/tests/src/Kernel/EventSpeakerEntityTest.php +++ b/modules/oe_content_event/modules/oe_content_event_person_reference/tests/src/Kernel/EventSpeakerEntityTest.php @@ -64,7 +64,7 @@ protected function setUp(): void { 'oe_content_person', 'oe_content_event_person_reference', ]); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); } diff --git a/modules/oe_content_event/src/Plugin/Validation/Constraint/EventFieldsRequiredValidator.php b/modules/oe_content_event/src/Plugin/Validation/Constraint/EventFieldsRequiredValidator.php index 5c0ad4679..f3c736bca 100644 --- a/modules/oe_content_event/src/Plugin/Validation/Constraint/EventFieldsRequiredValidator.php +++ b/modules/oe_content_event/src/Plugin/Validation/Constraint/EventFieldsRequiredValidator.php @@ -17,11 +17,11 @@ class EventFieldsRequiredValidator extends ConstraintValidator { * {@inheritdoc} */ public function validate($node, Constraint $constraint) { - /** @var \Drupal\node\NodeInterface $node */ if (!isset($node) || $node->getType() !== 'oe_event') { return; } + /** @var \Drupal\node\NodeInterface $node */ $this->validateRegistrationGroupFields($constraint, $node); $online_required_fields = [ diff --git a/modules/oe_content_event/tests/src/Kernel/EventKernelTestBase.php b/modules/oe_content_event/tests/src/Kernel/EventKernelTestBase.php index fe5a4c200..355eb343b 100644 --- a/modules/oe_content_event/tests/src/Kernel/EventKernelTestBase.php +++ b/modules/oe_content_event/tests/src/Kernel/EventKernelTestBase.php @@ -78,7 +78,7 @@ protected function setUp(): void { 'oe_content_social_media_links_field', 'oe_content_event', ]); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); } diff --git a/modules/oe_content_featured_media_field/src/Plugin/Field/FieldWidget/FeaturedMediaEntityBrowserWidget.php b/modules/oe_content_featured_media_field/src/Plugin/Field/FieldWidget/FeaturedMediaEntityBrowserWidget.php index 4acfd7de9..544c9bc90 100644 --- a/modules/oe_content_featured_media_field/src/Plugin/Field/FieldWidget/FeaturedMediaEntityBrowserWidget.php +++ b/modules/oe_content_featured_media_field/src/Plugin/Field/FieldWidget/FeaturedMediaEntityBrowserWidget.php @@ -345,6 +345,7 @@ protected function formElementItemsEntities(FieldItemListInterface $items, int $ // Determine if we're submitting and if submit came from this widget. $is_relevant_submit = FALSE; $triggering_element = $form_state->getTriggeringElement(); + $field_name_key = 2; if ($triggering_element) { $last_parent = end($triggering_element['#parents']); if (in_array($last_parent, [ @@ -363,7 +364,7 @@ protected function formElementItemsEntities(FieldItemListInterface $items, int $ $is_relevant_submit &= ($triggering_element['#parents'][$field_name_key] === $this->fieldDefinition->getName()) && (array_slice($triggering_element['#parents'], 0, count($element['#field_parents'])) == $element['#field_parents']); } - }; + } if ($is_relevant_submit) { // Submit was triggered by hidden "target_id" element when entities were diff --git a/modules/oe_content_organisation/tests/src/Kernel/OrganisationFieldTest.php b/modules/oe_content_organisation/tests/src/Kernel/OrganisationFieldTest.php index 6a7c2704c..84e68172e 100644 --- a/modules/oe_content_organisation/tests/src/Kernel/OrganisationFieldTest.php +++ b/modules/oe_content_organisation/tests/src/Kernel/OrganisationFieldTest.php @@ -57,7 +57,7 @@ protected function setUp(): void { 'oe_content_organisation', 'rdf_skos', ]); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); } diff --git a/modules/oe_content_persistent/src/Plugin/Filter/FilterPurl.php b/modules/oe_content_persistent/src/Plugin/Filter/FilterPurl.php index 1c480256e..88c37ad40 100755 --- a/modules/oe_content_persistent/src/Plugin/Filter/FilterPurl.php +++ b/modules/oe_content_persistent/src/Plugin/Filter/FilterPurl.php @@ -11,10 +11,12 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Url; +use Drupal\Core\Utility\Error; use Drupal\filter\FilterProcessResult; use Drupal\filter\Plugin\FilterBase; use Drupal\oe_content_persistent\ContentUrlResolverInterface; use Drupal\oe_content_persistent\ContentUuidResolverInterface; +use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -57,6 +59,13 @@ class FilterPurl extends FilterBase implements ContainerFactoryPluginInterface { */ protected $siteConfig; + /** + * A logger instance. + * + * @var \Psr\Log\LoggerInterface + */ + protected $logger; + /** * Constructs a new FilterPurl object. * @@ -72,13 +81,16 @@ class FilterPurl extends FilterBase implements ContainerFactoryPluginInterface { * The content UUID resolver service. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The configuration factory. + * @param \Psr\Log\LoggerInterface|null $logger + * A logger instance. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, ContentUrlResolverInterface $url_resolver, ContentUuidResolverInterface $uuid_resolver, ConfigFactoryInterface $config_factory) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, ContentUrlResolverInterface $url_resolver, ContentUuidResolverInterface $uuid_resolver, ConfigFactoryInterface $config_factory, ?LoggerInterface $logger = NULL) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->contentUrlResolver = $url_resolver; $this->contentUuidResolver = $uuid_resolver; $this->purlConfig = $config_factory->get('oe_content_persistent.settings'); $this->siteConfig = $config_factory->get('system.site'); + $this->logger = $logger; } /** @@ -91,7 +103,8 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_definition, $container->get('oe_content_persistent.url_resolver'), $container->get('oe_content_persistent.uuid_resolver'), - $container->get('config.factory') + $container->get('config.factory'), + $container->get('logger.factory')->get('filter_purl') ); } @@ -144,7 +157,7 @@ public function process($text, $langcode) { $result->addCacheableDependency($url); } catch (\Exception $e) { - watchdog_exception('filter_purl', $e); + Error::logException($this->logger, $e); } } diff --git a/modules/oe_content_persistent/src/Plugin/Linkit/Matcher/MediaPurlMatcher.php b/modules/oe_content_persistent/src/Plugin/Linkit/Matcher/MediaPurlMatcher.php index 9b2269a37..48401c95d 100644 --- a/modules/oe_content_persistent/src/Plugin/Linkit/Matcher/MediaPurlMatcher.php +++ b/modules/oe_content_persistent/src/Plugin/Linkit/Matcher/MediaPurlMatcher.php @@ -215,7 +215,7 @@ protected function buildDescription(EntityInterface $entity) { ], ]; $thumbnail = $entity->thumbnail->view($thumbnail_display_options); - $description_array[] = (string) $this->renderer->renderPlain( + $description_array[] = (string) $this->renderer->renderInIsolation( $thumbnail ); } diff --git a/modules/oe_content_person/tests/src/Kernel/PersonEntityTestBase.php b/modules/oe_content_person/tests/src/Kernel/PersonEntityTestBase.php index a4bbfe0ba..7c5a5ec92 100644 --- a/modules/oe_content_person/tests/src/Kernel/PersonEntityTestBase.php +++ b/modules/oe_content_person/tests/src/Kernel/PersonEntityTestBase.php @@ -75,7 +75,7 @@ protected function setUp(): void { $this->installSchema('node', ['node_access']); $this->installSchema('file', ['file_usage']); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); } diff --git a/modules/oe_content_person/tests/src/Kernel/PersonJobEntityTest.php b/modules/oe_content_person/tests/src/Kernel/PersonJobEntityTest.php index 06119bd92..ec01ce799 100644 --- a/modules/oe_content_person/tests/src/Kernel/PersonJobEntityTest.php +++ b/modules/oe_content_person/tests/src/Kernel/PersonJobEntityTest.php @@ -70,7 +70,7 @@ protected function setUp(): void { 'oe_content_person', ]); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); } diff --git a/modules/oe_content_publication/src/Plugin/Validation/Constraint/PublicationFieldsRequiredValidator.php b/modules/oe_content_publication/src/Plugin/Validation/Constraint/PublicationFieldsRequiredValidator.php index e75782364..31834fa47 100644 --- a/modules/oe_content_publication/src/Plugin/Validation/Constraint/PublicationFieldsRequiredValidator.php +++ b/modules/oe_content_publication/src/Plugin/Validation/Constraint/PublicationFieldsRequiredValidator.php @@ -16,11 +16,11 @@ class PublicationFieldsRequiredValidator extends ConstraintValidator { * {@inheritdoc} */ public function validate($node, Constraint $constraint) { - /** @var \Drupal\node\NodeInterface $node */ if (!isset($node) || $node->getType() !== 'oe_publication') { return; } + /** @var \Drupal\node\NodeInterface $node */ $is_collection = (bool) $node->get('oe_publication_collection')->value; if ($is_collection && $node->get('oe_publication_publications')->isEmpty()) { diff --git a/modules/oe_content_publication/tests/src/Kernel/PublicationEntityTest.php b/modules/oe_content_publication/tests/src/Kernel/PublicationEntityTest.php index 8a17f686d..a800f4f87 100644 --- a/modules/oe_content_publication/tests/src/Kernel/PublicationEntityTest.php +++ b/modules/oe_content_publication/tests/src/Kernel/PublicationEntityTest.php @@ -67,9 +67,9 @@ protected function setUp(): void { $this->installEntitySchema($entity); } - module_load_include('install', 'oe_content_documents_field'); + $this->container->get('module_handler')->loadInclude('oe_content_documents_field', 'install'); oe_content_documents_field_install(FALSE); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); $this->installConfig([ diff --git a/modules/oe_content_sub_entity/modules/oe_content_sub_entity_author/tests/src/Kernel/AuthorSkosUpdaterTest.php b/modules/oe_content_sub_entity/modules/oe_content_sub_entity_author/tests/src/Kernel/AuthorSkosUpdaterTest.php index 70c96d6dc..5abeb44c0 100644 --- a/modules/oe_content_sub_entity/modules/oe_content_sub_entity_author/tests/src/Kernel/AuthorSkosUpdaterTest.php +++ b/modules/oe_content_sub_entity/modules/oe_content_sub_entity_author/tests/src/Kernel/AuthorSkosUpdaterTest.php @@ -72,7 +72,7 @@ protected function setUp(): void { 'oe_content_sub_entity_author', 'oe_content_sub_entity_author_test', ]); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); } diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 000000000..bb9ec16fc --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,6 @@ +includes: + - ./vendor/openeuropa/code-review-drupal/dist/phpstan.drupal.neon +parameters: + excludePaths: + # Exclude the TimelineFieldProcessor due to very custom logic. + - modules/oe_content_timeline_field/src/TimelineFieldProcessor.php diff --git a/src/CallEntityWrapperBase.php b/src/CallEntityWrapperBase.php index 498b8811c..5f49843a5 100644 --- a/src/CallEntityWrapperBase.php +++ b/src/CallEntityWrapperBase.php @@ -15,6 +15,27 @@ abstract class CallEntityWrapperBase extends EntityWrapperBase implements CallEn use StringTranslationTrait; + /** + * Contains the entity bundle id. + * + * @var string + */ + protected $entityBundle = ''; + + /** + * Contains the Publication date field id. + * + * @var string + */ + protected $openingDate = ''; + + /** + * Contains the Deadline date field id. + * + * @var string + */ + protected $deadline = ''; + /** * {@inheritdoc} */ diff --git a/src/Form/EntityTypeForm.php b/src/Form/EntityTypeForm.php index 1979c423a..01ba5c7b2 100644 --- a/src/Form/EntityTypeForm.php +++ b/src/Form/EntityTypeForm.php @@ -116,6 +116,8 @@ public function save(array $form, FormStateInterface $form_state) { } $form_state->setRedirectUrl($entity_type->toUrl('collection')); + + return $status; } /** diff --git a/tests/src/Behat/Hook/Call/EntityAwareHookBase.php b/tests/src/Behat/Hook/Call/EntityAwareHookBase.php index 139273e2e..c2e65295d 100644 --- a/tests/src/Behat/Hook/Call/EntityAwareHookBase.php +++ b/tests/src/Behat/Hook/Call/EntityAwareHookBase.php @@ -20,6 +20,7 @@ public function filterMatches(HookScope $scope) { if ($scope instanceof EntityAwareHookScopeInterface) { return $scope->getEntityType() . '.' . $scope->getBundle() === $this->getFilterString(); } + return FALSE; } /** diff --git a/tests/src/Kernel/BaseFieldsTest.php b/tests/src/Kernel/BaseFieldsTest.php index e31e28c14..9f6251d25 100644 --- a/tests/src/Kernel/BaseFieldsTest.php +++ b/tests/src/Kernel/BaseFieldsTest.php @@ -39,7 +39,7 @@ protected function setUp(): void { $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installConfig(['field', 'node']); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); } diff --git a/tests/src/Kernel/ShortTitleTokenReplaceTest.php b/tests/src/Kernel/ShortTitleTokenReplaceTest.php index 2753477b9..d9468e8a7 100644 --- a/tests/src/Kernel/ShortTitleTokenReplaceTest.php +++ b/tests/src/Kernel/ShortTitleTokenReplaceTest.php @@ -48,7 +48,7 @@ protected function setUp(): void { $this->installEntitySchema('node'); $this->installSchema('node', 'node_access'); $this->installConfig(['field', 'filter', 'node', 'system']); - module_load_include('install', 'oe_content'); + $this->container->get('module_handler')->loadInclude('oe_content', 'install'); oe_content_install(FALSE); ConfigurableLanguage::createFromLangcode('fr')->save(); diff --git a/tests/src/Traits/EntityLoadingTrait.php b/tests/src/Traits/EntityLoadingTrait.php index 1693bd135..c3f844f52 100644 --- a/tests/src/Traits/EntityLoadingTrait.php +++ b/tests/src/Traits/EntityLoadingTrait.php @@ -19,13 +19,13 @@ trait EntityLoadingTrait { * Entity type ID. * @param string $label * Entity label. - * @param string|array $bundles + * @param array|string|null $bundles * Entity bundle ID, or array of entity bundle IDs. * * @return \Drupal\Core\Entity\EntityInterface * Entity object, if any. */ - protected function loadEntityByLabel(string $entity_type, string $label, $bundles = NULL): EntityInterface { + protected function loadEntityByLabel(string $entity_type, string $label, array|string|null $bundles = NULL): EntityInterface { $bundles = (array) $bundles; $storage = \Drupal::entityTypeManager()->getStorage($entity_type); $label_key = $storage->getEntityType()->getKey('label'); @@ -41,7 +41,7 @@ protected function loadEntityByLabel(string $entity_type, string $label, $bundle $entities = $storage->loadByProperties($properties); if (empty($entities)) { - $bundles = $bundles ?? 'of type ' . implode(', ', $bundles); + $bundles = 'of type ' . implode(', ', $bundles); throw new \InvalidArgumentException("No '$entity_type' entity {$bundles}with label '$label' has been found."); } diff --git a/tests/src/Traits/EntityReferenceRevisionTrait.php b/tests/src/Traits/EntityReferenceRevisionTrait.php index 3d5d246ef..f8a98a5e7 100644 --- a/tests/src/Traits/EntityReferenceRevisionTrait.php +++ b/tests/src/Traits/EntityReferenceRevisionTrait.php @@ -39,9 +39,11 @@ protected function getReferenceRevisionField(string $entity_type, string $bundle $revision_ids = []; foreach ($items as $item) { if ($target_entity_type_id === 'skos_concept') { + // @phpstan-ignore-next-line $entity = $this->loadSkosConceptEntityByLabel($item, $configuration['concept_schemes']); } else { + // @phpstan-ignore-next-line $entity = $this->loadEntityByLabel($target_entity_type_id, $item, $configuration['target_bundles']); } $ids[] = $entity->id(); diff --git a/tests/src/Traits/EntityReferenceTrait.php b/tests/src/Traits/EntityReferenceTrait.php index bb17b6a21..debcee490 100644 --- a/tests/src/Traits/EntityReferenceTrait.php +++ b/tests/src/Traits/EntityReferenceTrait.php @@ -40,9 +40,11 @@ protected function getReferenceField(string $entity_type, string $bundle, string $ids = []; foreach ($items as $item) { if ($target_entity_type_id === 'skos_concept') { + // @phpstan-ignore-next-line $entity = $this->loadSkosConceptEntityByLabel($item, $configuration['concept_schemes']); } else { + // @phpstan-ignore-next-line $entity = $this->loadEntityByLabel($target_entity_type_id, $item, $configuration['target_bundles']); } $ids[] = $entity->id();