From 9d6c73da99089975dba92c0a6a1879326e8cd4f6 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Fri, 21 Feb 2025 12:20:44 +0200 Subject: [PATCH] UHF-11071: Test external_entities v3 upgrade --- .../src/Plugin/Block/AnnouncementsBlock.php | 2 +- .../src/Plugin/Block/SurveyBlock.php | 2 +- .../StorageClient/Announcements.php | 2 +- .../EtusivuJsonApiEntityBase.php | 25 +++++++++++----- .../StorageClient/Surveys.php | 2 +- .../ExternalEntities/StorageClient/Events.php | 10 +++---- .../StorageClient/Hearings.php | 6 ++-- .../src/ElasticExternalEntityBase.php | 30 +++++++++++-------- .../ExternalEntities/StorageClient/News.php | 2 +- .../StorageClient/NewsGroups.php | 2 +- .../StorageClient/NewsNeighbourhoods.php | 2 +- .../StorageClient/NewsTags.php | 2 +- 12 files changed, 52 insertions(+), 35 deletions(-) diff --git a/modules/helfi_etusivu_entities/src/Plugin/Block/AnnouncementsBlock.php b/modules/helfi_etusivu_entities/src/Plugin/Block/AnnouncementsBlock.php index 6a56e006f..4f5a59436 100644 --- a/modules/helfi_etusivu_entities/src/Plugin/Block/AnnouncementsBlock.php +++ b/modules/helfi_etusivu_entities/src/Plugin/Block/AnnouncementsBlock.php @@ -68,7 +68,7 @@ protected function getRemoteEntities(): array { $entityStorage = $this->getExternalEntityStorage('helfi_announcements'); $nodes = []; - /** @var \Drupal\external_entities\ExternalEntityInterface $announcement */ + /** @var \Drupal\external_entities\Entity\ExternalEntityInterface $announcement */ foreach ($entityStorage->loadMultiple() as $announcement) { $linkUrl = NULL; $linkText = NULL; diff --git a/modules/helfi_etusivu_entities/src/Plugin/Block/SurveyBlock.php b/modules/helfi_etusivu_entities/src/Plugin/Block/SurveyBlock.php index e5d645c72..54d1469e3 100644 --- a/modules/helfi_etusivu_entities/src/Plugin/Block/SurveyBlock.php +++ b/modules/helfi_etusivu_entities/src/Plugin/Block/SurveyBlock.php @@ -98,7 +98,7 @@ protected function getRemoteEntities(): array { $entityStorage = $this->getExternalEntityStorage('helfi_surveys'); $nodes = []; - /** @var \Drupal\external_entities\ExternalEntityInterface $entity */ + /** @var \Drupal\external_entities\Entity\ExternalEntityInterface $entity */ foreach ($entityStorage->loadMultiple() as $entity) { $linkUrl = NULL; $linkText = NULL; diff --git a/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/Announcements.php b/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/Announcements.php index 22afae760..5d759c30d 100644 --- a/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/Announcements.php +++ b/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/Announcements.php @@ -7,7 +7,7 @@ /** * External entity storage client for News feed entities. * - * @ExternalEntityStorageClient( + * @StorageClient( * id = "helfi_announcements", * label = @Translation("Helfi: Announcements"), * description = @Translation("Retrieves announcements from helfi") diff --git a/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/EtusivuJsonApiEntityBase.php b/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/EtusivuJsonApiEntityBase.php index 490b784fd..b1bd20be5 100644 --- a/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/EtusivuJsonApiEntityBase.php +++ b/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/EtusivuJsonApiEntityBase.php @@ -9,8 +9,8 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Utility\Error; -use Drupal\external_entities\ExternalEntityInterface; -use Drupal\external_entities\StorageClient\ExternalEntityStorageClientBase; +use Drupal\external_entities\Entity\ExternalEntityInterface; +use Drupal\external_entities\StorageClient\StorageClientBase; use Drupal\helfi_api_base\Environment\Environment; use Drupal\helfi_api_base\Environment\Project; use Drupal\helfi_api_base\Language\DefaultLanguageResolver; @@ -20,15 +20,12 @@ use GuzzleHttp\Psr7\Query; use GuzzleHttp\Utils; use Psr\Log\LoggerAwareInterface; -use Psr\Log\LoggerAwareTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class for etusivu external entity storage client. */ -abstract class EtusivuJsonApiEntityBase extends ExternalEntityStorageClientBase implements LoggerAwareInterface { - - use LoggerAwareTrait; +abstract class EtusivuJsonApiEntityBase extends StorageClientBase implements LoggerAwareInterface { /** * Custom cache tag. @@ -92,7 +89,6 @@ public static function create( } catch (\InvalidArgumentException) { } - $instance->setLogger($container->get('logger.channel.helfi_etusivu_entities')); return $instance; } @@ -225,4 +221,19 @@ protected function queryDefaultLangcode(): array { ]; } + /** + * {@inheritDoc} + */ + public function transliterateDrupalFilters( + array $parameters, + array $context = [], + ) :array { + // @todo Check performance of this implementation UHF-11477. + return $this->transliterateDrupalFiltersAlter( + ['source' => [], 'drupal' => $parameters], + $parameters, + $context + ); + } + } diff --git a/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/Surveys.php b/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/Surveys.php index b5c329988..6b226d92c 100644 --- a/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/Surveys.php +++ b/modules/helfi_etusivu_entities/src/Plugin/ExternalEntities/StorageClient/Surveys.php @@ -7,7 +7,7 @@ /** * External entity storage client for News feed entities. * - * @ExternalEntityStorageClient( + * @StorageClient( * id = "helfi_surveys", * label = @Translation("Helfi: Surveys"), * description = @Translation("Retrieves surveys from helfi") diff --git a/modules/helfi_paragraphs_curated_event_list/src/Plugin/ExternalEntities/StorageClient/Events.php b/modules/helfi_paragraphs_curated_event_list/src/Plugin/ExternalEntities/StorageClient/Events.php index 6fd43f5e8..879b6e964 100644 --- a/modules/helfi_paragraphs_curated_event_list/src/Plugin/ExternalEntities/StorageClient/Events.php +++ b/modules/helfi_paragraphs_curated_event_list/src/Plugin/ExternalEntities/StorageClient/Events.php @@ -6,23 +6,23 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\external_entities\ExternalEntityInterface; -use Drupal\external_entities\StorageClient\ExternalEntityStorageClientBase; +use Drupal\external_entities\Entity\ExternalEntityInterface; +use Drupal\external_entities\StorageClient\StorageClientBase; use GuzzleHttp\ClientInterface; use GuzzleHttp\Utils; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Extrernal entity storage client for LinkedEvents events. + * External entity storage client for LinkedEvents events. * - * @ExternalEntityStorageClient( + * @StorageClient( * id = "linkedevents_events", * label = @Translation("LinkedEvents: Events"), * description = @Translation("Retrieves 'events' content from LinkedEvents") * ) */ -class Events extends ExternalEntityStorageClientBase { +class Events extends StorageClientBase { protected const API_URL = 'https://api.hel.fi/linkedevents/v1'; protected const EVENTS_BASE_URL = 'https://tapahtumat.hel.fi/'; diff --git a/modules/helfi_paragraphs_hearings/src/Plugin/ExternalEntities/StorageClient/Hearings.php b/modules/helfi_paragraphs_hearings/src/Plugin/ExternalEntities/StorageClient/Hearings.php index 1cfc6deb6..143d88f66 100644 --- a/modules/helfi_paragraphs_hearings/src/Plugin/ExternalEntities/StorageClient/Hearings.php +++ b/modules/helfi_paragraphs_hearings/src/Plugin/ExternalEntities/StorageClient/Hearings.php @@ -8,8 +8,8 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Url; -use Drupal\external_entities\ExternalEntityInterface; -use Drupal\external_entities\StorageClient\ExternalEntityStorageClientBase; +use Drupal\external_entities\Entity\ExternalEntityInterface; +use Drupal\external_entities\StorageClient\StorageClientBase; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\InvalidArgumentException; @@ -27,7 +27,7 @@ * description = @Translation("Retrieves hearings from hearing api") * ) */ -final class Hearings extends ExternalEntityStorageClientBase { +final class Hearings extends StorageClientBase { public const API_URL = 'https://kerrokantasi.api.hel.fi/v1/hearing?'; diff --git a/modules/helfi_paragraphs_news_list/src/ElasticExternalEntityBase.php b/modules/helfi_paragraphs_news_list/src/ElasticExternalEntityBase.php index 9a7d84935..6794d3611 100644 --- a/modules/helfi_paragraphs_news_list/src/ElasticExternalEntityBase.php +++ b/modules/helfi_paragraphs_news_list/src/ElasticExternalEntityBase.php @@ -5,18 +5,17 @@ namespace Drupal\helfi_paragraphs_news_list; use Drupal\Core\Utility\Error; -use Drupal\external_entities\ExternalEntityInterface; -use Drupal\external_entities\StorageClient\ExternalEntityStorageClientBase; +use Drupal\external_entities\Entity\ExternalEntityInterface; +use Drupal\external_entities\StorageClient\StorageClientBase; use Elastic\Elasticsearch\Client; use Elastic\Elasticsearch\Exception\ElasticsearchException; use Elastic\Transport\Exception\TransportException; -use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class used by taxonomy external entity. */ -abstract class ElasticExternalEntityBase extends ExternalEntityStorageClientBase { +abstract class ElasticExternalEntityBase extends StorageClientBase { /** * Which endpoint to query. @@ -32,13 +31,6 @@ abstract class ElasticExternalEntityBase extends ExternalEntityStorageClientBase */ protected Client $client; - /** - * The logger. - * - * @var \Psr\Log\LoggerInterface - */ - protected LoggerInterface $logger; - /** * {@inheritdoc} */ @@ -50,7 +42,6 @@ public static function create( ) : self { $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); $instance->client = $container->get('helfi_paragraphs_news_list.elastic_client'); - $instance->logger = $container->get('logger.factory')->get('helfi_external_entity'); return $instance; } @@ -280,4 +271,19 @@ public function query( return $data['hits']['hits']; } + /** + * {@inheritDoc} + */ + public function transliterateDrupalFilters( + array $parameters, + array $context = [], + ) :array { + // @todo Check performance of this implementation UHF-11477. + return $this->transliterateDrupalFiltersAlter( + ['source' => [], 'drupal' => $parameters], + $parameters, + $context + ); + } + } diff --git a/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/News.php b/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/News.php index a945c7f51..2ddf87154 100644 --- a/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/News.php +++ b/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/News.php @@ -9,7 +9,7 @@ /** * External entity storage client for News feed entities. * - * @ExternalEntityStorageClient( + * @StorageClient( * id = "helfi_news", * label = @Translation("Helfi: News"), * description = @Translation("Retrieves 'news' content from Helfi") diff --git a/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsGroups.php b/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsGroups.php index 3953ab8d5..41a59aa84 100644 --- a/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsGroups.php +++ b/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsGroups.php @@ -7,7 +7,7 @@ /** * External entity storage client for News groups taxonomy terms. * - * @ExternalEntityStorageClient( + * @StorageClient( * id = "helfi_news_groups", * label = @Translation("Helfi: News groups"), * description = @Translation("Retrieves news groups taxonomy terms from Helfi") diff --git a/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsNeighbourhoods.php b/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsNeighbourhoods.php index 86c54cd28..bb1b37330 100644 --- a/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsNeighbourhoods.php +++ b/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsNeighbourhoods.php @@ -7,7 +7,7 @@ /** * External entity storage client for News neighbourhoods taxonomy terms. * - * @ExternalEntityStorageClient( + * @StorageClient( * id = "helfi_news_neighbourhoods", * label = @Translation("Helfi: News neighbourhoods"), * description = @Translation("Retrieves news neighbourhoods taxonomy terms from Helfi") diff --git a/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsTags.php b/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsTags.php index ff0a3cc21..0793d6f7e 100644 --- a/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsTags.php +++ b/modules/helfi_paragraphs_news_list/src/Plugin/ExternalEntities/StorageClient/NewsTags.php @@ -7,7 +7,7 @@ /** * External entity storage client for News tags taxonomy terms. * - * @ExternalEntityStorageClient( + * @StorageClient( * id = "helfi_news_tags", * label = @Translation("Helfi: News tags"), * description = @Translation("Retrieves news tags taxonomy terms from Helfi")