Verified Commit 09561ef8 authored by Dave Long's avatar Dave Long
Browse files

refactor: #3608912 Move search updates back to search module and fix missing plugin errors

By: catch
By: godotislate
By: nicxvan
By: longwave
parent 411e46bd
Loading
Loading
Loading
Loading
Loading
+72 −0
Original line number Diff line number Diff line
@@ -14167,6 +14167,24 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/help/src/HelpTopicTwigLoader.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\help\\\\Plugin\\\\Search\\\\HelpSearch\\:\\:indexClear\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/help/src/Plugin/Search/HelpSearch.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\help\\\\Plugin\\\\Search\\\\HelpSearch\\:\\:markForReindex\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/help/src/Plugin/Search/HelpSearch.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\help\\\\Plugin\\\\Search\\\\HelpSearch\\:\\:updateIndex\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/help/src/Plugin/Search/HelpSearch.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\help\\\\Kernel\\\\HelpTopicTest\\:\\:assertBreadcrumb\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
@@ -19231,6 +19249,36 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/node/src/NodeViewBuilder.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\node\\\\Plugin\\\\Search\\\\NodeSearch\\:\\:indexClear\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/node/src/Plugin/Search/NodeSearch.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\node\\\\Plugin\\\\Search\\\\NodeSearch\\:\\:indexStatus\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/node/src/Plugin/Search/NodeSearch.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\node\\\\Plugin\\\\Search\\\\NodeSearch\\:\\:markForReindex\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/node/src/Plugin/Search/NodeSearch.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\node\\\\Plugin\\\\Search\\\\NodeSearch\\:\\:submitConfigurationForm\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/node/src/Plugin/Search/NodeSearch.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\node\\\\Plugin\\\\Search\\\\NodeSearch\\:\\:updateIndex\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/node/src/Plugin/Search/NodeSearch.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\node\\\\Plugin\\\\views\\\\argument\\\\Type\\:\\:node_type\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
@@ -20623,6 +20671,30 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/search/src/ViewsSearchQuery.php',
];
$ignoreErrors[] = [
	'message' => '#^Call to method execute\\(\\) of deprecated class Drupal\\\\node\\\\Plugin\\\\Search\\\\NodeSearch\\:
in drupal\\:11\\.4\\.0 and is removed from drupal\\:12\\.0\\.0\\. Instead, use
  \\\\Drupal\\\\search_node\\\\Plugin\\\\Search\\\\SearchNode\\.$#',
	'identifier' => 'method.deprecatedClass',
	'count' => 4,
	'path' => __DIR__ . '/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Call to method indexStatus\\(\\) of deprecated class Drupal\\\\node\\\\Plugin\\\\Search\\\\NodeSearch\\:
in drupal\\:11\\.4\\.0 and is removed from drupal\\:12\\.0\\.0\\. Instead, use
  \\\\Drupal\\\\search_node\\\\Plugin\\\\Search\\\\SearchNode\\.$#',
	'identifier' => 'method.deprecatedClass',
	'count' => 1,
	'path' => __DIR__ . '/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Call to method updateIndex\\(\\) of deprecated class Drupal\\\\node\\\\Plugin\\\\Search\\\\NodeSearch\\:
in drupal\\:11\\.4\\.0 and is removed from drupal\\:12\\.0\\.0\\. Instead, use
  \\\\Drupal\\\\search_node\\\\Plugin\\\\Search\\\\SearchNode\\.$#',
	'identifier' => 'method.deprecatedClass',
	'count' => 1,
	'path' => __DIR__ . '/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\serialization\\\\Encoder\\\\XmlEncoder\\:\\:setBaseEncoder\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+12 −0
Original line number Diff line number Diff line
@@ -11,3 +11,15 @@
function help_update_last_removed(): int {
  return 10200;
}

/**
 * Remove the help_search_items table.
 */
function help_update_11400(): void {
  // Drop the help_search_items table if search module is not installed.
  if (!\Drupal::moduleHandler()->moduleExists('search')) {
    if (\Drupal::database()->schema()->tableExists('help_search_items')) {
      \Drupal::database()->schema()->dropTable('help_search_items');
    }
  }
}
+1 −22
Original line number Diff line number Diff line
@@ -17,28 +17,7 @@ function help_removed_post_updates(): array {
}

/**
 * Update config entity dependencies to the Search Help module, if necessary.
 *
 * @see system_update_11400()
 * Moved to search_post_update_search_help_dependencies().
 */
function help_post_update_search_help_dependencies(): void {
  if (\Drupal::moduleHandler()->moduleExists('search')) {
    // @todo https://www.drupal.org/project/drupal/issues/3587570 Determine why
    //   the search.page.help_search config entity does not have a UUID in the
    //   11.3 test database dump. This means it is not discovered as a config
    //   entity dependency of the help module.
    $search_page_config = \Drupal::configFactory()->getEditable('search.page.help_search');
    if (!$search_page_config->isNew() && $search_page_config->get('uuid') === NULL) {
      $search_page_config->set('uuid', \Drupal::service('uuid')->generate())->save();
    }

    // Update the dependencies of all help config entities if they have
    // changed.
    foreach (\Drupal::service('config.manager')->findConfigEntityDependenciesAsEntities('module', ['help']) as $entity) {
      $dependencies = $entity->getDependencies();
      if ($entity->calculateDependencies()->getDependencies() !== $dependencies) {
        $entity->save();
      }
    }
  }
}
+197 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\help\Plugin\Search;

use Drupal\Core\Access\AccessibleInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Config\Config;
use Drupal\Core\Database\Connection;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\help\HelpSectionManager;
use Drupal\search\Attribute\Search;
use Drupal\search\Plugin\SearchIndexingInterface;
use Drupal\search\Plugin\SearchPluginBase;
use Drupal\search\SearchIndexInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Handles searching for help using the Search module index.
 *
 * Help items are indexed if their HelpSection plugin implements
 * \Drupal\help\HelpSearchInterface.
 *
 * @see \Drupal\help\HelpSearchInterface
 * @see \Drupal\help\HelpSectionPluginInterface
 *
 * @internal
 *   Plugin classes are internal.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Instead, use
 *   \Drupal\search_help\Plugin\Search\HelpSearch.
 * @see https://www.drupal.org/node/3581109
 */
#[Search(
  id: 'help_search',
  title: new TranslatableMarkup('Help'),
  use_admin_theme: TRUE,
)]
class HelpSearch extends SearchPluginBase implements AccessibleInterface, SearchIndexingInterface {

  /**
   * The current database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $database;

  /**
   * A config object for 'search.settings'.
   *
   * @var \Drupal\Core\Config\Config
   */
  protected $searchSettings;

  /**
   * The language manager.
   *
   * @var \Drupal\Core\Language\LanguageManagerInterface
   */
  protected $languageManager;

  /**
   * The Drupal account to use for checking for access to search.
   *
   * @var \Drupal\Core\Session\AccountInterface
   */
  protected $account;

  /**
   * The messenger.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * The state object.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * The help section plugin manager.
   *
   * @var \Drupal\help\HelpSectionManager
   */
  protected $helpSectionManager;

  /**
   * The search index.
   *
   * @var \Drupal\search\SearchIndexInterface
   */
  protected $searchIndex;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('database'),
      $container->get('config.factory')->get('search.settings'),
      $container->get('language_manager'),
      $container->get('messenger'),
      $container->get('current_user'),
      $container->get('state'),
      $container->get('plugin.manager.help_section'),
      $container->get('search.index')
    );
  }

  /**
   * Constructs a \Drupal\help_search\Plugin\Search\HelpSearch object.
   *
   * @param array $configuration
   *   Configuration for the plugin.
   * @param string $plugin_id
   *   The plugin ID for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Database\Connection $database
   *   The current database connection.
   * @param \Drupal\Core\Config\Config $search_settings
   *   A config object for 'search.settings'.
   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
   *   The language manager.
   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   *   The messenger.
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The $account object to use for checking for access to view help.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state object.
   * @param \Drupal\help\HelpSectionManager $help_section_manager
   *   The help section manager.
   * @param \Drupal\search\SearchIndexInterface $search_index
   *   The search index.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, Config $search_settings, LanguageManagerInterface $language_manager, MessengerInterface $messenger, AccountInterface $account, StateInterface $state, HelpSectionManager $help_section_manager, SearchIndexInterface $search_index) {
    @trigger_error(__CLASS__ . ' is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Instead, use \Drupal\search_help\Plugin\Search\HelpSearch. See https://www.drupal.org/node/3581109', E_USER_DEPRECATED);
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->database = $database;
    $this->searchSettings = $search_settings;
    $this->languageManager = $language_manager;
    $this->messenger = $messenger;
    $this->account = $account;
    $this->state = $state;
    $this->helpSectionManager = $help_section_manager;
    $this->searchIndex = $search_index;
  }

  /**
   * {@inheritdoc}
   */
  public function access($operation = 'view', ?AccountInterface $account = NULL, $return_as_object = FALSE) {
    return AccessResult::forbidden();
  }

  /**
   * {@inheritdoc}
   */
  public function execute() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function updateIndex() {
  }

  /**
   * {@inheritdoc}
   */
  public function indexClear() {
  }

  /**
   * {@inheritdoc}
   */
  public function markForReindex() {
  }

  /**
   * {@inheritdoc}
   */
  public function indexStatus() {
    return [];
  }

}
+111 −4
Original line number Diff line number Diff line
@@ -2,28 +2,69 @@

namespace Drupal\node\Plugin\Search;

use Drupal\Core\Access\AccessibleInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Config\Config;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\search\Attribute\Search;
use Drupal\search\Plugin\ConfigurableSearchPluginBase;
use Drupal\search\SearchIndexInterface;
use Drupal\search_node\Plugin\Search\SearchNode as CoreSearchNode;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Handles searching for node entities using the Search module index.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Instead, use
 *   \Drupal\search_node\Plugin\Search\SearchNode.
 *
 * @see https://www.drupal.org/node/3590298
 */
class NodeSearch extends CoreSearchNode {
#[Search(
  id: 'node_search',
  title: new TranslatableMarkup('Content'),
)]
class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInterface {

  /**
   * The messenger.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('database'),
      $container->get('entity_type.manager'),
      $container->get('module_handler'),
      $container->get('config.factory')->get('search.settings'),
      $container->get('language_manager'),
      $container->get('renderer'),
      $container->get('messenger'),
      $container->get('current_user'),
      $container->get('database.replica'),
      $container->get('search.index'),
      $container->get('entity_type.bundle.info'),
    );
  }

  /**
   * Constructs a \Drupal\node\Plugin\Search\NodeSearch object.
   */
  public function __construct(
    array $configuration,
    $plugin_id,
@@ -41,9 +82,75 @@ public function __construct(
    protected EntityTypeBundleInfoInterface $entityTypeBundleInfo,
  ) {
    @trigger_error(__CLASS__ . ' is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Instead, use \Drupal\search_node\Plugin\Search\SearchNode. See https://www.drupal.org/node/3590298', E_USER_DEPRECATED);
    parent::__construct($configuration, $plugin_id, $plugin_definition, $this->database, $this->entityTypeManager, $this->moduleHandler, $this->searchSettings, $this->languageManager, $this->renderer, $messenger, $this->account, $this->databaseReplica, $this->searchIndex, $this->entityTypeBundleInfo);
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->setMessenger($messenger);
    $this->addCacheTags(['node_list']);
  }

  /**
   * {@inheritdoc}
   */
  public function access($operation = 'view', ?AccountInterface $account = NULL, $return_as_object = FALSE) {
    return AccessResult::forbidden();
  }

  /**
   * {@inheritdoc}
   */
  public function isSearchExecutable() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function execute() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function updateIndex() {
  }

  /**
   * {@inheritdoc}
   */
  public function indexClear() {
  }

  /**
   * {@inheritdoc}
   */
  public function markForReindex() {
  }

  /**
   * {@inheritdoc}
   */
  public function indexStatus() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

}
Loading