diff --git a/modules/search_api_db/search_api_db_defaults/tests/src/Functional/IntegrationTest.php b/modules/search_api_db/search_api_db_defaults/tests/src/Functional/IntegrationTest.php index 0f193e52..a0dbd85d 100644 --- a/modules/search_api_db/search_api_db_defaults/tests/src/Functional/IntegrationTest.php +++ b/modules/search_api_db/search_api_db_defaults/tests/src/Functional/IntegrationTest.php @@ -5,7 +5,7 @@ namespace Drupal\Tests\search_api_db_defaults\Functional; use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; +use Drupal\Tests\field\Traits\EntityReferenceTestTrait; use Drupal\search_api\Entity\Index; use Drupal\search_api\Entity\Server; use Drupal\Tests\BrowserTestBase; diff --git a/search_api.drush.inc b/search_api.drush.inc deleted file mode 100644 index 808e373e..00000000 --- a/search_api.drush.inc +++ /dev/null @@ -1,449 +0,0 @@ - 'List all search indexes.', - 'examples' => [ - 'drush search-api-list' => dt('List all search indexes.'), - 'drush sapi-l' => dt('Alias to list all search indexes.'), - ], - 'aliases' => ['sapi-l'], - ]; - - $items['search-api-enable'] = [ - 'description' => 'Enable one or more disabled search indexes.', - 'examples' => [ - 'drush search-api-enable node_index' => dt('Enable the search index with the ID @name.', ['@name' => 'node_index']), - 'drush sapi-en node_index' => dt('Alias to enable the search index with the ID @name.', ['@name' => 'node_index']), - ], - 'arguments' => $index, - 'aliases' => ['sapi-en'], - ]; - - $items['search-api-enable-all'] = [ - 'description' => 'Enable all disabled search indexes.', - 'examples' => [ - 'drush search-api-enable-all' => dt('Enable all disabled indexes.'), - 'drush sapi-ena' => dt('Alias to enable all disabled indexes.'), - ], - 'arguments' => [], - 'aliases' => ['sapi-ena'], - ]; - - $items['search-api-disable'] = [ - 'description' => 'Disable one or more enabled search indexes.', - 'examples' => [ - 'drush search-api-disable node_index' => dt('Disable the search index with the ID @name.', ['@name' => 'node_index']), - 'drush sapi-dis node_index' => dt('Alias to disable the search index with the ID @name.', ['@name' => 'node_index']), - ], - 'arguments' => $index, - 'aliases' => ['sapi-dis'], - ]; - - $items['search-api-disable-all'] = [ - 'description' => 'Disable all enabled search indexes.', - 'examples' => [ - 'drush search-api-disable-all' => dt('Disable all enabled indexes.'), - 'drush sapi-disa' => dt('Alias to disable all enabled indexes.'), - ], - 'arguments' => [], - 'aliases' => ['sapi-disa'], - ]; - - $items['search-api-status'] = [ - 'description' => 'Show the status of one or all search indexes.', - 'examples' => [ - 'drush search-api-status' => dt('Show the status of all search indexes.'), - 'drush sapi-s' => dt('Alias to show the status of all search indexes.'), - 'drush sapi-s node_index' => dt('Show the status of the search index with the ID @name.', ['@name' => 'node_index']), - ], - 'arguments' => $index, - 'aliases' => ['sapi-s'], - ]; - - $items['search-api-index'] = [ - 'description' => 'Index items for one or all enabled search indexes.', - 'examples' => [ - 'drush search-api-index' => dt('Index all items for all enabled indexes.'), - 'drush sapi-i' => dt('Alias to index all items for all enabled indexes.'), - 'drush sapi-i node_index' => dt('Index all items for the index with the ID @name.', ['@name' => 'node_index']), - 'drush sapi-i node_index 100' => dt('Index a maximum number of @limit items for the index with the ID @name.', ['@limit' => 100, '@name' => 'node_index']), - 'drush sapi-i node_index 100 10' => dt('Index a maximum number of @limit items (@batch_size items per batch run) for the index with the ID @name.', ['@limit' => 100, '@batch_size' => 10, '@name' => 'node_index']), - ], - 'options' => [ - 'limit' => dt('The number of items to index. Set to 0 to index all items. Defaults to 0 (index all).'), - 'batch-size' => dt('The number of items to index per batch run. Set to 0 to index all items at once. Defaults to the "!batch_size_label" setting of the index.', ['!batch_size_label' => dt('Cron batch size')]), - ], - 'arguments' => $index, - 'aliases' => ['sapi-i'], - ]; - - $items['search-api-reset-tracker'] = [ - 'description' => 'Force reindexing of one or all search indexes, without deleting existing index data.', - 'examples' => [ - 'drush search-api-reindex' => dt('Schedule all search indexes for reindexing.'), - 'drush sapi-r' => dt('Alias to schedule all search indexes for reindexing .'), - 'drush sapi-r node_index' => dt('Schedule the search index with the ID @name for reindexing.', ['@name' => 'node_index']), - ], - 'options' => [ - 'entity-types' => [ - 'description' => dt('List of entity type ids to reset tracker for.'), - 'example_value' => 'user,node', - ], - ], - 'arguments' => $index, - 'aliases' => [ - 'search-api-mark-all', - 'search-api-reindex', - 'sapi-r', - ], - ]; - - $items['search-api-clear'] = [ - 'description' => 'Clear one or all search indexes and mark them for reindexing.', - 'examples' => [ - 'drush search-api-clear' => dt('Clear all search indexes.'), - 'drush sapi-c' => dt('Alias to clear all search indexes.'), - 'drush sapi-c node_index' => dt('Clear the search index with the ID @name.', ['@name' => 'node_index']), - ], - 'arguments' => $index, - 'aliases' => ['sapi-c'], - ]; - - $items['search-api-search'] = [ - 'description' => 'Search for a keyword or phrase in a given index.', - 'examples' => [ - 'drush search-api-search node_index title' => dt('Search for "title" inside the "node_index" index.'), - 'drush sapi-search node_index title' => dt('Alias to search for "title" inside the "node_index" index.'), - ], - 'arguments' => $index + [ - 'keyword' => dt('The keyword to look for.'), - ], - 'aliases' => ['sapi-search'], - ]; - - $items['search-api-server-list'] = [ - 'description' => 'List all search servers.', - 'examples' => [ - 'drush search-api-server-list' => dt('List all search servers.'), - 'drush sapi-sl' => dt('Alias to list all search servers.'), - ], - 'aliases' => ['sapi-sl'], - ]; - - $items['search-api-server-enable'] = [ - 'description' => 'Enable a search server.', - 'examples' => [ - 'drush search-api-server-e my_solr_server' => dt('Enable the @server search server.', ['@server' => 'my_solr_server']), - 'drush sapi-se my_solr_server' => dt('Alias to enable the @server search server.', ['@server' => 'my_solr_server']), - ], - 'arguments' => $server, - 'aliases' => ['sapi-se'], - ]; - - $items['search-api-server-disable'] = [ - 'description' => 'Disable a search server.', - 'examples' => [ - 'drush search-api-server-disable' => dt('Disable the @server search server.', ['@server' => 'my_solr_server']), - 'drush sapi-sd' => dt('Alias to disable the @server search server.', ['@server' => 'my_solr_server']), - ], - 'arguments' => $server, - 'aliases' => ['sapi-sd'], - ]; - - $items['search-api-server-clear'] = [ - 'description' => 'Clear all search indexes on the search server and mark them for reindexing.', - 'examples' => [ - 'drush search-api-server-clear' => dt('Clear all search indexes on the search server @server.', ['@server' => 'my_solr_server']), - 'drush sapi-sc' => dt('Alias to clear all search indexes on the search server @server.', ['@server' => 'my_solr_server']), - ], - 'arguments' => $server, - 'aliases' => ['sapi-sc'], - ]; - - $items['search-api-set-index-server'] = [ - 'description' => 'Set the search server used by a given index.', - 'examples' => [ - 'drush search-api-set-index-server default_node_index my_solr_server' => dt('Set the @index index to used the @server server.', ['@index' => 'default_node_index', '@server' => 'my_solr_server']), - 'drush sapi-sis default_node_index my_solr_server' => dt('Alias to set the @index index to used the @server server.', ['@index' => 'default_node_index', '@server' => 'my_solr_server']), - ], - 'arguments' => $index + $server, - 'aliases' => ['sapi-sis'], - ]; - - return $items; -} - -/** - * Prints a list of all search indexes. - */ -function drush_search_api_list() { - $command_helper = _search_api_drush_command_helper(); - $rows[] = [ - dt('ID'), - dt('Name'), - dt('Server'), - dt('Type'), - dt('Status'), - dt('Limit'), - ]; - $rows += $command_helper->indexListCommand(); - foreach ($rows as &$row) { - $row['types'] = is_array($row['types']) ? implode(', ', $row['types']) : $row['types']; - $row['typeNames'] = is_array($row['types']) ? implode(', ', $row['typeNames']) : $row['types']; - } - drush_print_table($rows); -} - -/** - * Enables one or more search indexes. - * - * @param string|null $index_id - * The ID of a search index to enable. Or NULL (only used internally) to - * enable all disabled indexes. - */ -function drush_search_api_enable($index_id = NULL) { - $command_helper = _search_api_drush_command_helper(); - try { - $command_helper->enableIndexCommand([$index_id]); - } - catch (ConsoleException $exception) { - drush_set_error($exception->getMessage()); - } -} - -/** - * Enables all search indexes. - */ -function drush_search_api_enable_all() { - $command_helper = _search_api_drush_command_helper(); - try { - $command_helper->enableIndexCommand(); - } - catch (ConsoleException $exception) { - drush_set_error($exception->getMessage()); - } -} - -/** - * Disables one or more search indexes. - * - * @param string|null $index_id - * The ID of a search index to disable. Or NULL (only used internally) to - * disable all enabled indexes. - */ -function drush_search_api_disable($index_id = NULL) { - $command_helper = _search_api_drush_command_helper(); - try { - $command_helper->disableIndexCommand([$index_id]); - } - catch (ConsoleException $exception) { - drush_set_error($exception->getMessage()); - } -} - -/** - * Disables all search indexes. - */ -function drush_search_api_disable_all() { - $command_helper = _search_api_drush_command_helper(); - try { - $command_helper->disableIndexCommand(); - } - catch (ConsoleException $exception) { - drush_set_error($exception->getMessage()); - } -} - -/** - * Displays the status of one or all search indexes. - * - * @param string|null $index_id - * (optional) The ID of the search index whose status should be displayed, or - * NULL to display the status of all search indexes. - */ -function drush_search_api_status($index_id = NULL) { - $command_helper = _search_api_drush_command_helper(); - $rows[] = [ - dt('ID'), - dt('Name'), - dt('% Complete'), - dt('Indexed'), - dt('Total'), - ]; - $rows += $command_helper->indexStatusCommand([$index_id]); - - drush_print_table($rows); -} - -/** - * Indexes items. - * - * @param string|null $index_id - * (optional) The index ID for which items should be indexed, or NULL to index - * items on all indexes. - */ -function drush_search_api_index($index_id = NULL) { - $command_helper = _search_api_drush_command_helper(); - $limit = drush_get_option('limit'); - $batch_size = drush_get_option('batch-size'); - - $batch_set = $command_helper->indexItemsToIndexCommand([$index_id], $limit, $batch_size); - if ($batch_set) { - drush_backend_batch_process(); - } -} - -/** - * Schedules a search index for reindexing. - * - * @param string|null $index_id - * (optional) The index ID for which items should be reindexed, or NULL to - * reindex all search indexes. - */ -function drush_search_api_reset_tracker($index_id = NULL) { - $command_helper = _search_api_drush_command_helper(); - $entity_types = drush_get_option_list('entity-types'); - $command_helper->resetTrackerCommand([$index_id], $entity_types); -} - -/** - * Clears a search index. - * - * @param string|null $index_id - * (optional) The ID of the search index which should be cleared, or NULL to - * clear all search indexes. - */ -function drush_search_api_clear($index_id = NULL) { - $command_helper = _search_api_drush_command_helper(); - $command_helper->clearIndexCommand([$index_id]); -} - -/** - * Executes a simple keyword search and displays the results in a table. - * - * @param string $index_id - * The ID of the index being searched. - * @param string $keyword - * The search keyword. - */ -function drush_search_api_search($index_id, $keyword) { - $command_helper = _search_api_drush_command_helper(); - $rows = $command_helper->searchIndexCommand($index_id, $keyword); - drush_print_table($rows); -} - -/** - * Lists all available search servers. - */ -function drush_search_api_server_list() { - $command_helper = _search_api_drush_command_helper(); - $rows[] = [ - dt('ID'), - dt('Name'), - dt('Status'), - ]; - - try { - $rows += $command_helper->serverListCommand(); - } - catch (ConsoleException $exception) { - drush_print($exception->getMessage()); - } - - drush_print_table($rows); -} - -/** - * Enables a search server. - * - * @param string $server_id - * The ID of the server to enable. - */ -function drush_search_api_server_enable($server_id = NULL) { - $command_helper = _search_api_drush_command_helper(); - try { - $command_helper->enableServerCommand($server_id); - } - catch (ConsoleException $exception) { - drush_print($exception->getMessage()); - } -} - -/** - * Disables a search server. - * - * @param string $server_id - * The ID of the server to disable. - */ -function drush_search_api_server_disable($server_id = NULL) { - $command_helper = _search_api_drush_command_helper(); - try { - $command_helper->disableServerCommand($server_id); - } - catch (ConsoleException $exception) { - drush_print($exception->getMessage()); - } -} - -/** - * Clears all search indexes on the server and marks them for reindexing. - * - * @param string $server_id - * The ID of the server to clear all search indexes. - */ -function drush_search_api_server_clear($server_id = NULL) { - $command_helper = _search_api_drush_command_helper(); - try { - $command_helper->clearServerCommand($server_id); - } - catch (ConsoleException $exception) { - drush_print($exception->getMessage()); - } -} - -/** - * Sets the server for a given index. - * - * @param string $index_id - * The ID of the index whose server should be changed. - * @param string $server_id - * The ID of the new server for the index. - */ -function drush_search_api_set_index_server($index_id = NULL, $server_id = NULL) { - $command_helper = _search_api_drush_command_helper(); - try { - $command_helper->setIndexServerCommand($index_id, $server_id); - } - catch (ConsoleException $exception) { - drush_print($exception->getMessage()); - } -} - -/** - * Returns an instance of the command helper. - * - * @return \Drupal\search_api\Utility\CommandHelper - * An instance of the command helper class. - */ -function _search_api_drush_command_helper() { - $command_helper = new CommandHelper(\Drupal::entityTypeManager(), \Drupal::moduleHandler(), \Drupal::service('event_dispatcher'), 'dt'); - $command_helper->setLogger(\Drupal::logger('search_api')); - return $command_helper; -} diff --git a/search_api.services.yml b/search_api.services.yml index b2add071..c67add92 100644 --- a/search_api.services.yml +++ b/search_api.services.yml @@ -5,7 +5,7 @@ services: paramconverter.search_api: class: Drupal\search_api\ParamConverter\SearchApiConverter - arguments: ['@entity.manager', '@tempstore.shared', '@current_user'] + arguments: ['@entity_type.manager', '@entity.repository', '@tempstore.shared', '@current_user'] tags: - { name: paramconverter, priority: 10 } lazy: true diff --git a/src/Form/IndexBreakLockForm.php b/src/Form/IndexBreakLockForm.php index 66e942ee..ad69e9ec 100644 --- a/src/Form/IndexBreakLockForm.php +++ b/src/Form/IndexBreakLockForm.php @@ -93,7 +93,8 @@ class IndexBreakLockForm extends EntityConfirmFormBase { */ public function getDescription() { $locked = $this->tempStore->getMetadata($this->entity->id()); - $account = $this->entityTypeManager->getStorage('user')->load($locked->owner); + $owner_id = $locked->getOwnerId(); + $account = $this->entityTypeManager->getStorage('user')->load($owner_id); $username = [ '#theme' => 'username', '#account' => $account, diff --git a/src/ParamConverter/SearchApiConverter.php b/src/ParamConverter/SearchApiConverter.php index a3929bf0..f0ce1589 100644 --- a/src/ParamConverter/SearchApiConverter.php +++ b/src/ParamConverter/SearchApiConverter.php @@ -2,13 +2,16 @@ namespace Drupal\search_api\ParamConverter; +use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityRepositoryInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\ParamConverter\EntityConverter; use Drupal\Core\ParamConverter\ParamConverterInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\search_api\UnsavedIndexConfiguration; use Drupal\Core\TempStore\SharedTempStoreFactory; +use Drupal\search_api\UnsavedIndexConfiguration; use Symfony\Component\Routing\Route; /** @@ -38,15 +41,17 @@ class SearchApiConverter extends EntityConverter implements ParamConverterInterf /** * Constructs a new SearchApiConverter. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. + * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository + * The entity repository. * @param \Drupal\Core\TempStore\SharedTempStoreFactory $temp_store_factory * The factory for the temp store object. * @param \Drupal\Core\Session\AccountInterface $user * The current user. */ - public function __construct(EntityManagerInterface $entity_manager, SharedTempStoreFactory $temp_store_factory, AccountInterface $user) { - parent::__construct($entity_manager); + public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository, SharedTempStoreFactory $temp_store_factory, AccountInterface $user) { + parent::__construct($entity_type_manager, $entity_repository); $this->tempStoreFactory = $temp_store_factory; $this->currentUser = $user; @@ -57,7 +62,16 @@ class SearchApiConverter extends EntityConverter implements ParamConverterInterf */ public function convert($value, $definition, $name, array $defaults) { /** @var \Drupal\search_api\IndexInterface $entity */ - $storage = $this->entityManager->getStorage('search_api_index'); + try { + $storage = $this->entityTypeManager->getStorage('search_api_index'); + } + // @todo Use a multi-catch once we depend on PHP 7.1+. + catch (InvalidPluginDefinitionException $e) { + return NULL; + } + catch (PluginNotFoundException $e) { + return NULL; + } if (!($storage instanceof ConfigEntityStorageInterface)) { return NULL; } @@ -71,10 +85,11 @@ class SearchApiConverter extends EntityConverter implements ParamConverterInterf $store = $this->tempStoreFactory->get('search_api_index'); $current_user_id = $this->currentUser->id() ?: session_id(); /** @var \Drupal\search_api\IndexInterface|\Drupal\search_api\UnsavedIndexConfiguration $index */ - if ($index = $store->get($value)) { + $index = $store->get($value); + if ($index) { $index = new UnsavedIndexConfiguration($index, $store, $current_user_id); $index->setLockInformation($store->getMetadata($value)); - $index->setEntityTypeManager($this->entityManager); + $index->setEntityTypeManager($this->entityTypeManager); } // Otherwise, create a new temporary copy of the search index. else { diff --git a/src/Plugin/ConfigurablePluginInterface.php b/src/Plugin/ConfigurablePluginInterface.php index 44d3b5af..02990c4a 100644 --- a/src/Plugin/ConfigurablePluginInterface.php +++ b/src/Plugin/ConfigurablePluginInterface.php @@ -2,7 +2,8 @@ namespace Drupal\search_api\Plugin; -use Drupal\Component\Plugin\ConfigurablePluginInterface as DrupalConfigurablePluginInterface; +use Drupal\Component\Plugin\ConfigurableInterface; +use Drupal\Component\Plugin\DependentPluginInterface; use Drupal\Component\Plugin\DerivativeInspectionInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -16,7 +17,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; * @see \Drupal\Core\Plugin\PluginFormInterface * @see \Drupal\search_api\Plugin\PluginFormTrait */ -interface ConfigurablePluginInterface extends HideablePluginInterface, PluginInspectionInterface, DerivativeInspectionInterface, DrupalConfigurablePluginInterface, ContainerFactoryPluginInterface { +interface ConfigurablePluginInterface extends HideablePluginInterface, PluginInspectionInterface, DerivativeInspectionInterface, ConfigurableInterface, DependentPluginInterface, ContainerFactoryPluginInterface { /** * Returns the label for use on the administration pages. diff --git a/src/Plugin/PluginFormTrait.php b/src/Plugin/PluginFormTrait.php index 331391be..e9bb8ec8 100644 --- a/src/Plugin/PluginFormTrait.php +++ b/src/Plugin/PluginFormTrait.php @@ -2,6 +2,7 @@ namespace Drupal\search_api\Plugin; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface as DrupalConfigurablePluginInterface; use Drupal\Core\Form\FormStateInterface; @@ -38,7 +39,8 @@ trait PluginFormTrait { * @see \Drupal\Core\Plugin\PluginFormInterface::submitConfigurationForm() */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - if ($this instanceof DrupalConfigurablePluginInterface) { + // @todo Clean this up once we depend on Drupal 9.0+. + if ($this instanceof ConfigurableInterface || $this instanceof DrupalConfigurablePluginInterface) { $this->setConfiguration($form_state->getValues()); } } diff --git a/src/Plugin/views/EntityFieldRenderer.php b/src/Plugin/views/EntityFieldRenderer.php index fe858a30..0d42f708 100644 --- a/src/Plugin/views/EntityFieldRenderer.php +++ b/src/Plugin/views/EntityFieldRenderer.php @@ -108,7 +108,7 @@ class EntityFieldRenderer extends ViewsEntityFieldRenderer { */ protected function getEntityTranslationRenderer() { if (!isset($this->entityTranslationRenderer)) { - $entity_type = $this->getEntityManager() + $entity_type = $this->getEntityTypeManager() ->getDefinition($this->getEntityTypeId()); $this->entityTranslationRenderer = new EntityTranslationRenderer($this->view, $this->getLanguageManager(), $entity_type); } diff --git a/src/Plugin/views/field/SearchApiEntity.php b/src/Plugin/views/field/SearchApiEntity.php index c54a2c21..812b2b4d 100644 --- a/src/Plugin/views/field/SearchApiEntity.php +++ b/src/Plugin/views/field/SearchApiEntity.php @@ -4,6 +4,7 @@ namespace Drupal\search_api\Plugin\views\field; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityTypeBundleInfo; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TypedData\TranslatableInterface; use Drupal\views\FieldAPIHandlerTrait; @@ -28,6 +29,13 @@ class SearchApiEntity extends SearchApiStandard { */ protected $entityDisplayRepository; + /** + * The entity type bundle info. + * + * @var \Drupal\Core\Entity\EntityTypeBundleInfo|null + */ + protected $entityTypeBundleInfo; + /** * {@inheritdoc} */ @@ -36,6 +44,7 @@ class SearchApiEntity extends SearchApiStandard { $field = parent::create($container, $configuration, $plugin_id, $plugin_definition); $field->setEntityDisplayRepository($container->get('entity_display.repository')); + $field->setEntityTypeBundleInfo($container->get('entity_type.bundle.info')); return $field; } @@ -63,6 +72,29 @@ class SearchApiEntity extends SearchApiStandard { return $this; } + /** + * Retrieves the entity type bundle info. + * + * @return \Drupal\Core\Entity\EntityTypeBundleInfo + * The entity type bundle info. + */ + public function getEntityTypeBundleInfo() { + return $this->entityTypeBundleInfo ?: \Drupal::service('entity_type.bundle.info'); + } + + /** + * Sets the entity type bundle info. + * + * @param \Drupal\Core\Entity\EntityTypeBundleInfo $entity_type_bundle_info + * The new entity type bundle info. + * + * @return $this + */ + public function setEntityTypeBundleInfo(EntityTypeBundleInfo $entity_type_bundle_info) { + $this->entityTypeBundleInfo = $entity_type_bundle_info; + return $this; + } + /** * {@inheritdoc} */ @@ -84,7 +116,8 @@ class SearchApiEntity extends SearchApiStandard { $view_modes = []; $bundles = []; if ($entity_type_id) { - $bundles = $this->getEntityManager()->getBundleInfo($entity_type_id); + $bundles = $this->getEntityTypeBundleInfo() + ->getBundleInfo($entity_type_id); // In case the field definition specifies the bundles to expect, restrict // the displayed bundles to those. $settings = $this->getFieldDefinition()->getSettings(); @@ -197,7 +230,7 @@ class SearchApiEntity extends SearchApiStandard { return; } - $entities = $this->getEntityManager() + $entities = $this->getEntityTypeManager() ->getStorage($this->getTargetEntityTypeId()) ->loadMultiple(array_keys($to_load)); $account = $this->getQuery()->getAccessAccount(); @@ -283,7 +316,7 @@ class SearchApiEntity extends SearchApiStandard { } $view_mode = $this->options['display_methods'][$bundle]['view_mode']; - $build = $this->getEntityManager() + $build = $this->getEntityFieldManager() ->getViewBuilder($entity->getEntityTypeId()) ->view($entity, $view_mode); return [ diff --git a/src/Plugin/views/field/SearchApiEntityField.php b/src/Plugin/views/field/SearchApiEntityField.php index b3a039bc..d8493a4c 100644 --- a/src/Plugin/views/field/SearchApiEntityField.php +++ b/src/Plugin/views/field/SearchApiEntityField.php @@ -278,8 +278,8 @@ class SearchApiEntityField extends EntityField { } } if (!isset($this->entityFieldRenderer)) { - $entity_type = $this->entityManager->getDefinition($this->getEntityType()); - $this->entityFieldRenderer = new EntityFieldRenderer($this->view, $this->relationship, $this->languageManager, $entity_type, $this->entityManager); + $entity_type = $this->entityTypeManager->getDefinition($this->getEntityType()); + $this->entityFieldRenderer = new EntityFieldRenderer($this->view, $this->relationship, $this->languageManager, $entity_type, $this->entityTypeManager); $this->entityFieldRenderer ->setDatasourceId($this->getDatasourceId()) ->setParentPath($this->getParentPath()); diff --git a/src/Plugin/views/field/SearchApiEntityOperations.php b/src/Plugin/views/field/SearchApiEntityOperations.php index 90bfd892..d9b8fa79 100644 --- a/src/Plugin/views/field/SearchApiEntityOperations.php +++ b/src/Plugin/views/field/SearchApiEntityOperations.php @@ -4,6 +4,8 @@ namespace Drupal\search_api\Plugin\views\field; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\TypedData\ComplexDataInterface; +use Drupal\search_api\LoggerTrait; +use Drupal\search_api\SearchApiException; use Drupal\views\Plugin\views\field\EntityOperations; use Drupal\views\ResultRow; @@ -16,17 +18,25 @@ use Drupal\views\ResultRow; */ class SearchApiEntityOperations extends EntityOperations { + use LoggerTrait; + /** * {@inheritdoc} */ public function render(ResultRow $values) { $build = []; - $entity = $this->getContainedEntity($values->_item->getOriginalObject()); + try { + $entity = $this->getContainedEntity($values->_item->getOriginalObject()); + } + catch (SearchApiException $e) { + $this->logException($e); + return $build; + } if ($entity) { $entity_type = $entity->getEntityType(); if ($entity_type->hasListBuilderClass()) { - $operations = $this->entityManager->getListBuilder($entity_type->id()) + $operations = $this->entityTypeManager->getListBuilder($entity_type->id()) ->getOperations($entity); if ($this->options['destination']) { foreach ($operations as $i => $operation) { diff --git a/src/Plugin/views/field/SearchApiNumeric.php b/src/Plugin/views/field/SearchApiNumeric.php index e0333881..78cbf952 100644 --- a/src/Plugin/views/field/SearchApiNumeric.php +++ b/src/Plugin/views/field/SearchApiNumeric.php @@ -2,7 +2,7 @@ namespace Drupal\search_api\Plugin\views\field; -use Drupal\Core\StringTranslation\PluralTranslatableMarkup; +use Drupal\Component\Gettext\PoItem; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\field\MultiItemsFieldHandlerInterface; use Drupal\views\Plugin\views\field\NumericField; @@ -29,7 +29,7 @@ class SearchApiNumeric extends NumericField implements MultiItemsFieldHandlerInt // submitOptionsForm() method won't be called, which means the // "format_plural_string" option won't be saved correctly. Fix that here. if (isset($options['format_plural_values'])) { - $options['format_plural_string'] = implode(PluralTranslatableMarkup::DELIMITER, $options['format_plural_values']); + $options['format_plural_string'] = implode(PoItem::DELIMITER, $options['format_plural_values']); } parent::init($view, $display, $options); diff --git a/src/Processor/FieldsProcessorPluginBase.php b/src/Processor/FieldsProcessorPluginBase.php index eb857fab..b06c1f7c 100644 --- a/src/Processor/FieldsProcessorPluginBase.php +++ b/src/Processor/FieldsProcessorPluginBase.php @@ -7,6 +7,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; use Drupal\Core\Render\Element; use Drupal\Core\Render\ElementInfoManagerInterface; +use Drupal\Core\Security\TrustedCallbackInterface; use Drupal\search_api\Item\FieldInterface; use Drupal\search_api\Utility\DataTypeHelperInterface; use Drupal\search_api\Plugin\PluginFormTrait; @@ -41,7 +42,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * - preprocess_index * - preprocess_query */ -abstract class FieldsProcessorPluginBase extends ProcessorPluginBase implements PluginFormInterface { +abstract class FieldsProcessorPluginBase extends ProcessorPluginBase implements PluginFormInterface, TrustedCallbackInterface { use PluginFormTrait; @@ -118,6 +119,13 @@ abstract class FieldsProcessorPluginBase extends ProcessorPluginBase implements return $this; } + /** + * {@inheritdoc} + */ + public static function trustedCallbacks() { + return ['preRenderFieldsCheckboxes']; + } + /** * {@inheritdoc} */ diff --git a/src/UnsavedConfigurationInterface.php b/src/UnsavedConfigurationInterface.php index d0138a02..6cb77a0a 100644 --- a/src/UnsavedConfigurationInterface.php +++ b/src/UnsavedConfigurationInterface.php @@ -67,11 +67,23 @@ interface UnsavedConfigurationInterface { /** * Saves the changes represented by this object permanently. + * + * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException + * Thrown if the "search_api_index" storage handler couldn't be loaded. + * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException + * Thrown if the "search_api_index" entity type doesn't exist. + * @throws \Drupal\Core\Entity\EntityStorageException + * Thrown if saving the index failed. + * @throws \Drupal\Core\TempStore\TempStoreException + * Thrown when a lock for the temp storage could not be acquired. */ public function savePermanent(); /** * Discards the changes represented by this object. + * + * @throws \Drupal\Core\TempStore\TempStoreException + * Thrown when a lock for the temp storage could not be acquired. */ public function discardChanges(); diff --git a/src/UnsavedIndexConfiguration.php b/src/UnsavedIndexConfiguration.php index 3d801200..74c22d0b 100644 --- a/src/UnsavedIndexConfiguration.php +++ b/src/UnsavedIndexConfiguration.php @@ -2,11 +2,14 @@ namespace Drupal\search_api; +use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\TempStore\TempStoreException; use Drupal\search_api\Datasource\DatasourceInterface; use Drupal\search_api\Entity\Index; use Drupal\search_api\Item\FieldInterface; @@ -45,7 +48,7 @@ class UnsavedIndexConfiguration implements IndexInterface, UnsavedConfigurationI /** * The lock information for this configuration. * - * @var object|null + * @var \Drupal\Core\TempStore\Lock|null */ protected $lock; @@ -115,7 +118,7 @@ class UnsavedIndexConfiguration implements IndexInterface, UnsavedConfigurationI */ public function isLocked() { if ($this->lock) { - return $this->lock->owner != $this->currentUserId; + return $this->lock->getOwnerId() != $this->currentUserId; } return FALSE; } @@ -127,15 +130,24 @@ class UnsavedIndexConfiguration implements IndexInterface, UnsavedConfigurationI if (!$this->lock) { return NULL; } - $uid = is_numeric($this->lock->owner) ? $this->lock->owner : 0; - return $this->getEntityTypeManager()->getStorage('user')->load($uid); + $owner_id = $this->lock->getOwnerId(); + $uid = is_numeric($owner_id) ? $owner_id : 0; + try { + return $this->getEntityTypeManager()->getStorage('user')->load($uid); + } + catch (InvalidPluginDefinitionException $e) { + return NULL; + } + catch (PluginNotFoundException $e) { + return NULL; + } } /** * {@inheritdoc} */ public function getLastUpdated() { - return $this->lock ? $this->lock->updated : NULL; + return $this->lock ? $this->lock->getUpdated() : NULL; } /** @@ -859,8 +871,13 @@ class UnsavedIndexConfiguration implements IndexInterface, UnsavedConfigurationI * {@inheritdoc} */ public function save() { - if ($this->tempStore->setIfOwner($this->entity->id(), $this->entity)) { - return SAVED_UPDATED; + try { + if ($this->tempStore->setIfOwner($this->entity->id(), $this->entity)) { + return SAVED_UPDATED; + } + } + catch (TempStoreException $e) { + throw new EntityStorageException('Could not save temporary index configuration: ' . $e->getMessage(), $e->getCode(), $e); } throw new EntityStorageException('Cannot save temporary index configuration: currently being edited by someone else.'); } diff --git a/tests/src/Functional/ProcessorIntegrationTest.php b/tests/src/Functional/ProcessorIntegrationTest.php index 9d974ef6..efc8f04a 100644 --- a/tests/src/Functional/ProcessorIntegrationTest.php +++ b/tests/src/Functional/ProcessorIntegrationTest.php @@ -5,7 +5,7 @@ namespace Drupal\Tests\search_api\Functional; use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; +use Drupal\Tests\field\Traits\EntityReferenceTestTrait; use Drupal\search_api\Entity\Index; use Drupal\search_api\Entity\Server; use Drupal\search_api\Item\Field; diff --git a/tests/src/Functional/ViewsTest.php b/tests/src/Functional/ViewsTest.php index f17bff6a..09f8b1da 100644 --- a/tests/src/Functional/ViewsTest.php +++ b/tests/src/Functional/ViewsTest.php @@ -321,7 +321,8 @@ class ViewsTest extends SearchApiBrowserTestBase { $this->assertArrayHasKey('views_rest:search_api_test_view__rest_export_1', $displays, 'A display plugin was created for the test view block display.'); $this->assertEquals('/search-api-test', $displays[$display_id]->getPath(), 'Display returns the correct path.'); $view_url = Url::fromUserInput('/search-api-test')->toString(); - $this->assertEquals($view_url, $displays[$display_id]->getUrl()->toString(), 'Display returns the correct URL.'); + $display_url = Url::fromUserInput($displays[$display_id]->getPath())->toString(); + $this->assertEquals($view_url, $display_url, 'Display returns the correct URL.'); $this->assertNull($displays['views_block:search_api_test_view__block_1']->getPath(), 'Block display returns the correct path.'); $this->assertEquals('/search-api-rest-test', $displays['views_rest:search_api_test_view__rest_export_1']->getPath(), 'REST display returns the correct path.'); diff --git a/tests/src/Kernel/ConfigEntity/DependencyRemovalTest.php b/tests/src/Kernel/ConfigEntity/DependencyRemovalTest.php index c6e68c46..f5772e92 100644 --- a/tests/src/Kernel/ConfigEntity/DependencyRemovalTest.php +++ b/tests/src/Kernel/ConfigEntity/DependencyRemovalTest.php @@ -4,7 +4,7 @@ namespace Drupal\Tests\search_api\Kernel\ConfigEntity; use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface; -use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; +use Drupal\Tests\field\Traits\EntityReferenceTestTrait; use Drupal\KernelTests\KernelTestBase; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; diff --git a/tests/src/Kernel/Processor/AddHierarchyTest.php b/tests/src/Kernel/Processor/AddHierarchyTest.php index be602245..86163f40 100644 --- a/tests/src/Kernel/Processor/AddHierarchyTest.php +++ b/tests/src/Kernel/Processor/AddHierarchyTest.php @@ -3,13 +3,13 @@ namespace Drupal\Tests\search_api\Kernel\Processor; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; +use Drupal\Tests\field\Traits\EntityReferenceTestTrait; use Drupal\node\Entity\NodeType; use Drupal\search_api\Item\Field; use Drupal\search_api\Query\Query; use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\Tests\search_api\Kernel\ResultsTrait; -use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; /** * Tests the "Hierarchy" processor. diff --git a/tests/src/Kernel/Processor/ProcessorTestBase.php b/tests/src/Kernel/Processor/ProcessorTestBase.php index 1a77c0bd..84c49aa3 100644 --- a/tests/src/Kernel/Processor/ProcessorTestBase.php +++ b/tests/src/Kernel/Processor/ProcessorTestBase.php @@ -7,7 +7,6 @@ use Drupal\search_api\Entity\Index; use Drupal\search_api\Entity\Server; use Drupal\search_api\Item\Field; use Drupal\search_api\Utility\Utility; -use Drupal\system\Entity\Action; /** * Provides a base class for Drupal unit tests for processors. @@ -74,12 +73,6 @@ abstract class ProcessorTestBase extends KernelTestBase { $this->installConfig(['field']); $this->installConfig('search_api'); - Action::create([ - 'id' => 'foo', - 'label' => 'Foobaz', - 'plugin' => 'comment_publish_action', - ])->save(); - // Do not use a batch for tracking the initial items after creating an // index when running the tests via the GUI. Otherwise, it seems Drupal's // Batch API gets confused and the test fails. diff --git a/tests/src/Kernel/System/CommandHelperTest.php b/tests/src/Kernel/System/CommandHelperTest.php index 24399797..266ad9de 100644 --- a/tests/src/Kernel/System/CommandHelperTest.php +++ b/tests/src/Kernel/System/CommandHelperTest.php @@ -176,7 +176,7 @@ class CommandHelperTest extends KernelTestBase { $index = Index::load('second_index'); $this->assertTrue($index->status()); - $this->setExpectedException(ConsoleException::class); + $this->expectException(ConsoleException::class); $this->systemUnderTest->enableIndexCommand(['foo']); } @@ -192,7 +192,7 @@ class CommandHelperTest extends KernelTestBase { $index->delete(); } - $this->setExpectedException(ConsoleException::class); + $this->expectException(ConsoleException::class); $this->systemUnderTest->enableIndexCommand(['second_index']); } @@ -222,7 +222,7 @@ class CommandHelperTest extends KernelTestBase { $index = Index::load('test_index'); $this->assertFalse($index->status()); - $this->setExpectedException(ConsoleException::class); + $this->expectException(ConsoleException::class); $this->systemUnderTest->disableIndexCommand(['foo']); } @@ -299,7 +299,7 @@ class CommandHelperTest extends KernelTestBase { $this->assertSame('disabled', (string) $result['test_server']['status']); $server->delete(); - $this->setExpectedException(ConsoleException::class); + $this->expectException(ConsoleException::class); $this->systemUnderTest->serverListCommand(); } @@ -318,7 +318,7 @@ class CommandHelperTest extends KernelTestBase { $server = Server::load('test_server'); $this->assertTrue($server->status()); - $this->setExpectedException(ConsoleException::class); + $this->expectException(ConsoleException::class); $this->systemUnderTest->enableServerCommand('foo'); } @@ -333,7 +333,7 @@ class CommandHelperTest extends KernelTestBase { $server = Server::load('test_server'); $this->assertFalse($server->status()); - $this->setExpectedException(ConsoleException::class); + $this->expectException(ConsoleException::class); $this->systemUnderTest->enableServerCommand('foo'); } @@ -376,7 +376,7 @@ class CommandHelperTest extends KernelTestBase { * @covers ::setIndexServerCommand */ public function testSetIndexServerCommandWithInvalidIndex() { - $this->setExpectedException(ConsoleException::class); + $this->expectException(ConsoleException::class); $this->systemUnderTest->setIndexServerCommand('foo', 'test_server'); } @@ -386,7 +386,7 @@ class CommandHelperTest extends KernelTestBase { * @covers ::setIndexServerCommand */ public function testSetIndexServerCommandWithInvalidServer() { - $this->setExpectedException(ConsoleException::class); + $this->expectException(ConsoleException::class); $this->systemUnderTest->setIndexServerCommand('test_index', 'bar'); } diff --git a/tests/src/Kernel/Views/TaxonomyTermArgumentTest.php b/tests/src/Kernel/Views/TaxonomyTermArgumentTest.php index cdf26722..593f7aaf 100644 --- a/tests/src/Kernel/Views/TaxonomyTermArgumentTest.php +++ b/tests/src/Kernel/Views/TaxonomyTermArgumentTest.php @@ -4,7 +4,7 @@ namespace Drupal\Tests\search_api\Kernel\Views; use Drupal\KernelTests\KernelTestBase; use Drupal\search_api\Plugin\views\argument\SearchApiTerm; -use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; /** * Tests whether the SearchApiTerm plugin works correctly. diff --git a/tests/src/Unit/Processor/EntityStatusTest.php b/tests/src/Unit/Processor/EntityStatusTest.php index 4e84876c..179dce76 100644 --- a/tests/src/Unit/Processor/EntityStatusTest.php +++ b/tests/src/Unit/Processor/EntityStatusTest.php @@ -97,7 +97,7 @@ class EntityStatusTest extends UnitTestCase { $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); $entity_type_manager->method('getDefinition') ->willReturnCallback(function ($entity_type_id) use ($self) { - $entity_type = $self->getMock(EntityTypeInterface::class); + $entity_type = $self->createMock(EntityTypeInterface::class); $publishable = in_array($entity_type_id, ['node', 'comment']); $entity_type->method('entityClassImplements') ->willReturnMap([