diff --git a/composer.json b/composer.json index a201da9cde92f94c85b4fcb94a99d7e594f7b650..ece67d8c3564beb3bfc5a53ab0b89832e63d9c79 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,6 @@ }, "require-dev": { "drupal/token": "^1", - "drush/drush": "^12" + "drush/drush": "^12 || ^13" } } diff --git a/src/Commands/TaxonomyEntityIndexCommands.php b/src/Commands/TaxonomyEntityIndexCommands.php index 53e58b2121a1e1604d51934f0a4a87a5686c35a1..5e3ab1c2c7af9c06d2a2fe0d276e274318aac978 100644 --- a/src/Commands/TaxonomyEntityIndexCommands.php +++ b/src/Commands/TaxonomyEntityIndexCommands.php @@ -4,6 +4,7 @@ namespace Drupal\taxonomy_entity_index\Commands; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drush\Commands\DrushCommands; /** @@ -101,7 +102,7 @@ class TaxonomyEntityIndexCommands extends DrushCommands { } $batch = [ - 'title' => t('Updating @num item(s)', ['@num' => $numOperations]), + 'title' => new TranslatableMarkup('Updating @num item(s)', ['@num' => $numOperations]), 'operations' => $operations, 'finished' => '\Drupal\taxonomy_entity_index\BatchService::processEntityTypeReindexFinished', ]; diff --git a/src/Form/TaxonomyEntityIndexAdminForm.php b/src/Form/TaxonomyEntityIndexAdminForm.php index ed83bbd072917afe6502a62e8f5aac299db65411..4f42a4b57a2a0ee84b66c93472138793ffd3593e 100644 --- a/src/Form/TaxonomyEntityIndexAdminForm.php +++ b/src/Form/TaxonomyEntityIndexAdminForm.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Drupal\taxonomy_entity_index\Form; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; @@ -18,13 +19,15 @@ final class TaxonomyEntityIndexAdminForm extends ConfigFormBase { /** * Creates a TaxonomyEntityIndexAdminForm form. * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager - * The entity manager service. * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory * The factory for configuration objects. + * @param \Drupal\Core\Config\TypedConfigManagerInterface $typedConfigManager + * The interface for managing config schema type plugins. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager + * The entity manager service. */ - public function __construct(protected EntityTypeManagerInterface $entityTypeManager, ConfigFactoryInterface $configFactory) { - parent::__construct($configFactory); + public function __construct(ConfigFactoryInterface $configFactory, TypedConfigManagerInterface $typedConfigManager, protected EntityTypeManagerInterface $entityTypeManager) { + parent::__construct($configFactory, $typedConfigManager); } /** @@ -32,8 +35,9 @@ final class TaxonomyEntityIndexAdminForm extends ConfigFormBase { */ public static function create(ContainerInterface $container): static { return new static( - $container->get('entity_type.manager'), - $container->get('config.factory') + $container->get('config.factory'), + $container->get('config.typed'), + $container->get('entity_type.manager') ); } diff --git a/src/Plugin/views/argument/TaxonomyEntityIndexDepth.php b/src/Plugin/views/argument/TaxonomyEntityIndexDepth.php index f8f266e50479fee93929b02ba99e9515a9d8dea0..362c25d14e5254972ed7e1d19aaee625cbc2369f 100644 --- a/src/Plugin/views/argument/TaxonomyEntityIndexDepth.php +++ b/src/Plugin/views/argument/TaxonomyEntityIndexDepth.php @@ -4,11 +4,9 @@ declare(strict_types=1); namespace Drupal\taxonomy_entity_index\Plugin\views\argument; -use Drupal\Component\Utility\DeprecationHelper; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\Condition; use Drupal\Core\Entity\EntityRepositoryInterface; -use Drupal\Core\Entity\EntityStorageInterface; use Drupal\taxonomy\Plugin\views\argument\IndexTidDepth; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; @@ -32,14 +30,8 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth { /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $termStorage, protected Connection $database, protected EntityStorageInterface|EntityRepositoryInterface $entityRepository) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $termStorage); - DeprecationHelper::backwardsCompatibleCall( - \Drupal::VERSION, - '10.3', - fn () => parent::__construct($configuration, $plugin_id, $plugin_definition, $this->entityRepository), - fn () => parent::__construct($configuration, $plugin_id, $plugin_definition, $termStorage) - ); + public function __construct(array $configuration, $plugin_id, $plugin_definition, protected Connection $database, protected EntityRepositoryInterface $entityRepository) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $this->entityRepository); } /** @@ -50,7 +42,6 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth { $configuration, $plugin_id, $plugin_definition, - $container->get('entity_type.manager')->getStorage('taxonomy_term'), $container->get('database'), $container->get('entity.repository') ); @@ -59,7 +50,7 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth { /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->baseTableInfo = $this->viewsData->get($this->table); } @@ -73,7 +64,7 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth { return FALSE; } - [$operator, $ids] = $this->getOperatorAndIds(); + [, $ids] = $this->getOperatorAndIds(); if (!$tids = $this->convertIdsToEntityIds($ids)) { $tids = [-1]; } @@ -91,7 +82,7 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth { } $or = new Condition('OR'); - $where = $or->condition('tn.tid', $tids, $operator); + $where = $or->condition('tn.tid', $tids, 'IN'); $last = "tn"; if ($this->options['depth'] > 0) { @@ -99,14 +90,14 @@ abstract class TaxonomyEntityIndexDepth extends IndexTidDepth { $last = "th"; foreach (range(1, abs((int) $this->options['depth'])) as $count) { $subquery->leftJoin('taxonomy_term__parent', "th$count", "$last.parent_target_id = th$count.entity_id"); - $where->condition("th$count.entity_id", $tids, $operator); + $where->condition("th$count.entity_id", $tids, 'IN'); $last = "th$count"; } } elseif ($this->options['depth'] < 0) { foreach (range(1, abs((int) $this->options['depth'])) as $count) { $subquery->leftJoin('taxonomy_term__parent', "th$count", "$last.entity_id = th$count.parent_target_id"); - $where->condition("th$count.entity_id", $tids, $operator); + $where->condition("th$count.entity_id", $tids, 'IN'); $last = "th$count"; } } diff --git a/src/Plugin/views/field/TaxonomyEntityIndexTid.php b/src/Plugin/views/field/TaxonomyEntityIndexTid.php index 9a512de7af95372b19db2366738c3f0a7dc70514..c8297fb2d075b9adc05204fa01a43ad3663bd534 100644 --- a/src/Plugin/views/field/TaxonomyEntityIndexTid.php +++ b/src/Plugin/views/field/TaxonomyEntityIndexTid.php @@ -59,7 +59,7 @@ final class TaxonomyEntityIndexTid extends TaxonomyIndexTid { /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); // Reset the variables which are set by the parent class. diff --git a/src/Plugin/views/filter/TaxonomyEntityIndexTidDepth.php b/src/Plugin/views/filter/TaxonomyEntityIndexTidDepth.php index 74447f8b587067dcc8c909702d40f7bef493fe57..d37351f014afe65c3aacc820a2aa9a61f8ea5cc5 100644 --- a/src/Plugin/views/filter/TaxonomyEntityIndexTidDepth.php +++ b/src/Plugin/views/filter/TaxonomyEntityIndexTidDepth.php @@ -61,7 +61,7 @@ class TaxonomyEntityIndexTidDepth extends TaxonomyIndexTidDepth implements Conta /** * {@inheritdoc} */ - public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { + public function init(ViewExecutable $view, DisplayPluginBase $display, ?array &$options = NULL) { parent::init($view, $display, $options); $this->baseTableInfo = $this->viewsData->get($this->table); } @@ -121,14 +121,14 @@ class TaxonomyEntityIndexTidDepth extends TaxonomyIndexTidDepth implements Conta if ($this->options['depth'] > 0) { $subquery->leftJoin('taxonomy_term__parent', 'th', "th.entity_id = tei.tid"); $last = "th"; - foreach (range(1, abs((int)$this->options['depth'])) as $count) { + foreach (range(1, abs((int) $this->options['depth'])) as $count) { $subquery->leftJoin('taxonomy_term__parent', "th$count", "$last.parent_target_id = th$count.entity_id"); $where->condition("th$count.entity_id", $this->value, $operator); $last = "th$count"; } } elseif ($this->options['depth'] < 0) { - foreach (range(1, abs((int)$this->options['depth'])) as $count) { + foreach (range(1, abs((int) $this->options['depth'])) as $count) { $subquery->leftJoin('taxonomy_term__parent', "th$count", "$last.entity_id = th$count.parent_target_id"); $where->condition("th$count.entity_id", $this->value, $operator); $last = "th$count"; diff --git a/taxonomy_entity_index.info.yml b/taxonomy_entity_index.info.yml index 562a58c503e36420c68abf9835c9e7650819ba7e..281b85f0a4a75aab4de8ad83dc40dcd95581575f 100644 --- a/taxonomy_entity_index.info.yml +++ b/taxonomy_entity_index.info.yml @@ -1,7 +1,7 @@ name: 'Taxonomy Entity Index' description: 'Provides an actual entity to term index table for lookups.' -core_version_requirement: ^8 || ^9 || ^10 || ^11 +core_version_requirement: ^10.3 || ^11 dependencies: - - taxonomy + - drupal:taxonomy type: module configure: taxonomy_entity_index.admin diff --git a/taxonomy_entity_index.module b/taxonomy_entity_index.module index d63e308b2895ff539bb182ba1737233085a87987..116fc52d2f7f40f850c5cb8ad1cb52e1a69dbc38 100644 --- a/taxonomy_entity_index.module +++ b/taxonomy_entity_index.module @@ -72,6 +72,14 @@ function taxonomy_entity_index_entity_insert(EntityInterface $entity) { */ function taxonomy_entity_index_entity_update(EntityInterface $entity) { $entity_type_id = $entity->getEntityTypeId(); + if (!$entity instanceof ContentEntityInterface) { + return; + } + $target_type_info = \Drupal::entityTypeManager()->getDefinition($entity_type_id); + $id_definition = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($entity_type_id)[$target_type_info->getKey('id')]; + if ($id_definition->getType() !== 'integer') { + return; + } $config = \Drupal::config('taxonomy_entity_index.settings'); $entity_types_to_index = $config->get('types'); diff --git a/tests/modules/taxonomy_entity_index_test_views/taxonomy_entity_index_test_views.info.yml b/tests/modules/taxonomy_entity_index_test_views/taxonomy_entity_index_test_views.info.yml index 5a60e7bc36f29d87b0c869bf5afda4b62ef7a6fb..737d9c8f51e5609a49fc4ca48a977e95ac00a586 100644 --- a/tests/modules/taxonomy_entity_index_test_views/taxonomy_entity_index_test_views.info.yml +++ b/tests/modules/taxonomy_entity_index_test_views/taxonomy_entity_index_test_views.info.yml @@ -3,8 +3,7 @@ type: module description: 'Provides default views for views taxonomy entity index tests.' package: Testing version: VERSION -core: 8.x -core_version_requirement: ^8 || ^9 || ^10 +core_version_requirement: ^10 || ^11 dependencies: - drupal:taxonomy_entity_index - drupal:taxonomy diff --git a/tests/modules/taxonomy_entity_index_test_views/test_views/views.view.test_argument_taxonomy_entity_index_index_tid_depth.yml b/tests/modules/taxonomy_entity_index_test_views/test_views/views.view.test_argument_taxonomy_entity_index_index_tid_depth.yml index 905cab9de02267e785a84ada2b52acbbb756cd28..7f096c6bd36ee326be41a32cf35de4e88338687e 100644 --- a/tests/modules/taxonomy_entity_index_test_views/test_views/views.view.test_argument_taxonomy_entity_index_index_tid_depth.yml +++ b/tests/modules/taxonomy_entity_index_test_views/test_views/views.view.test_argument_taxonomy_entity_index_index_tid_depth.yml @@ -179,7 +179,6 @@ display: default_argument_type: fixed default_argument_options: argument: '' - default_argument_skip_url: false summary_options: base_path: '' count: true diff --git a/tests/modules/taxonomy_entity_index_test_views/test_views/views.view.test_argument_taxonomy_entity_index_uuid.yml b/tests/modules/taxonomy_entity_index_test_views/test_views/views.view.test_argument_taxonomy_entity_index_uuid.yml index 747ba9e0a232bc2ba21553b36a4694ce17afab8a..03a60d787296b4e39bcc7f52b9ec33af16b93201 100644 --- a/tests/modules/taxonomy_entity_index_test_views/test_views/views.view.test_argument_taxonomy_entity_index_uuid.yml +++ b/tests/modules/taxonomy_entity_index_test_views/test_views/views.view.test_argument_taxonomy_entity_index_uuid.yml @@ -209,7 +209,6 @@ display: default_argument_type: fixed default_argument_options: argument: '' - default_argument_skip_url: false summary_options: base_path: '' count: true diff --git a/tests/src/Functional/Views/TaxonomyEntityIndexTermArgumentDepthTest.php b/tests/src/Functional/Views/TaxonomyEntityIndexTermArgumentDepthTest.php index c2d05b3c9ba81a49ae628432acb30563cb175cb5..32e0d9c35dbee8056c07dff812b2b0dd385179fc 100644 --- a/tests/src/Functional/Views/TaxonomyEntityIndexTermArgumentDepthTest.php +++ b/tests/src/Functional/Views/TaxonomyEntityIndexTermArgumentDepthTest.php @@ -77,7 +77,7 @@ class TaxonomyEntityIndexTermArgumentDepthTest extends TaxonomyEntityIndexTestBa $this->nodes[] = $node; // Setup the media type. - $media_type = $this->setupMediaTypeWithTaxonomy(); + $this->setupMediaTypeWithTaxonomy(); // Create a file to upload to be used in the media item. $file = File::create([ @@ -122,7 +122,7 @@ class TaxonomyEntityIndexTermArgumentDepthTest extends TaxonomyEntityIndexTestBa * Creates a media type with a taxonomy field to use for testing. */ protected function setupMediaTypeWithTaxonomy() { - $media_type = $this->createMediaType('file', ['id' => 'document', 'label' => 'Document']); + $this->createMediaType('file', ['id' => 'document', 'label' => 'Document']); $handler_settings = [ 'target_bundles' => [