You are here

class AutoIndexNodeSearch in Auto Index 8

The method we wish to call on the original object IndexNodeSearch has a protected visibility applied, and therefore we are left with 2 options. Copy and paste the current functionality into this module or extend the existing class. We are extending the existing functionality, implementing it this way will ensure we inherrit all fixes applied to the original plugin.

Hierarchy

Expanded class hierarchy of AutoIndexNodeSearch

File

src/Plugin/Search/AutoIndexNodeSearch.php, line 15

Namespace

Drupal\auto_index\Plugin\Search
View source
class AutoIndexNodeSearch extends NodeSearch {

  /**
   * Add a public method to allow us to target single nodes outside of this class.
   * @param NodeInterface $node
   */
  public function indexSingleNode(NodeInterface $node) {

    // Ensure the
    $query = db_select('node', 'n', array(
      'target' => 'replica',
    ));
    $query
      ->addField('n', 'nid');
    $query
      ->leftJoin('search_dataset', 'sd', 'sd.sid = n.nid AND sd.type = :type', array(
      ':type' => $this
        ->getPluginId(),
    ));
    $query
      ->condition($query
      ->andConditionGroup()
      ->condition('n.nid', $node
      ->id())
      ->condition($query
      ->orConditionGroup()
      ->where('sd.sid IS NULL')
      ->condition('sd.reindex', 0, '<>')));
    $num_rows = $query
      ->countQuery()
      ->execute()
      ->fetchField();
    if ($num_rows < 1) {
      return;
    }

    // Use the implementation of indexNode from the plugin.
    $this
      ->indexNode($node);

    // Register a shutdown hook to ensure the totals get recalculated.
    drupal_register_shutdown_function('search_update_totals');
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['autoindex'] = array(
      '#type' => 'details',
      '#title' => $this
        ->t('Auto Indexing'),
      '#open' => TRUE,
    );
    $form['autoindex']['automatic_indexing'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Automatically index on Create/Update of content.'),
      '#default_value' => $this->configuration['automatic_indexing'],
    );
    return array_merge($form, parent::buildConfigurationForm($form, $form_state));
    return parent::buildConfigurationForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration['automatic_indexing'] = $form_state
      ->getValue([
      'automatic_indexing',
    ]);
    parent::buildConfigurationForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AutoIndexNodeSearch::buildConfigurationForm public function Form constructor. Overrides NodeSearch::buildConfigurationForm
AutoIndexNodeSearch::indexSingleNode public function Add a public method to allow us to target single nodes outside of this class.
AutoIndexNodeSearch::submitConfigurationForm public function Form submission handler. Overrides NodeSearch::submitConfigurationForm
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::getCacheContexts public function 3
CacheableDependencyTrait::getCacheMaxAge public function 3
CacheableDependencyTrait::getCacheTags public function 3
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
ConfigurableSearchPluginBase::$searchPageId protected property The unique ID for the search page using this plugin.
ConfigurableSearchPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
ConfigurableSearchPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ConfigurableSearchPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ConfigurableSearchPluginBase::setSearchPageId public function Sets the ID for the search page using this plugin. Overrides ConfigurableSearchPluginInterface::setSearchPageId
ConfigurableSearchPluginBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DeprecatedServicePropertyTrait::__get public function Allows to access deprecated/removed properties.
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
NodeSearch::$account protected property The Drupal account to use for checking for access to advanced search.
NodeSearch::$advanced protected property The list of options and info for advanced search filters.
NodeSearch::$database protected property The current database connection.
NodeSearch::$databaseReplica protected property The replica database connection.
NodeSearch::$deprecatedProperties protected property
NodeSearch::$entityTypeManager protected property The entity type manager.
NodeSearch::$languageManager protected property The language manager.
NodeSearch::$messenger protected property The messenger. Overrides MessengerTrait::$messenger
NodeSearch::$moduleHandler protected property A module manager object.
NodeSearch::$rankings protected property An array of additional rankings from hook_ranking().
NodeSearch::$renderer protected property The Renderer service to format the username and node.
NodeSearch::$searchIndex protected property The search index.
NodeSearch::$searchSettings protected property A config object for 'search.settings'.
NodeSearch::access public function Checks data value access. Overrides AccessibleInterface::access
NodeSearch::addNodeRankings protected function Adds the configured rankings to the search query.
NodeSearch::ADVANCED_FORM constant A constant for setting and checking the query string.
NodeSearch::buildSearchUrlQuery public function Builds the URL GET query parameters array for search. Overrides SearchPluginBase::buildSearchUrlQuery
NodeSearch::create public static function Creates an instance of the plugin. Overrides SearchPluginBase::create
NodeSearch::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableSearchPluginBase::defaultConfiguration
NodeSearch::execute public function Executes the search. Overrides SearchInterface::execute
NodeSearch::findResults protected function Queries to find search results, and sets status messages.
NodeSearch::getRankings protected function Gathers ranking definitions from hook_ranking().
NodeSearch::getType public function Returns the search index type this plugin uses. Overrides SearchPluginBase::getType
NodeSearch::indexClear public function Clears the search index for this plugin. Overrides SearchIndexingInterface::indexClear
NodeSearch::indexNode protected function Indexes a single node.
NodeSearch::indexStatus public function Reports the status of indexing. Overrides SearchIndexingInterface::indexStatus
NodeSearch::isSearchExecutable public function Verifies if the values set via setSearch() are valid and sufficient. Overrides SearchPluginBase::isSearchExecutable
NodeSearch::markForReindex public function Marks the search index for reindexing for this plugin. Overrides SearchIndexingInterface::markForReindex
NodeSearch::parseAdvancedDefaults protected function Parses the advanced search form default values.
NodeSearch::prepareResults protected function Prepares search results for rendering.
NodeSearch::removeSubmittedInfo public function Removes the submitted by information from the build array.
NodeSearch::searchFormAlter public function Alters the search form when being built for a given plugin. Overrides SearchPluginBase::searchFormAlter
NodeSearch::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
NodeSearch::updateIndex public function Updates the search index for this plugin. Overrides SearchIndexingInterface::updateIndex
NodeSearch::__construct public function Constructs a \Drupal\node\Plugin\Search\NodeSearch object. Overrides ConfigurableSearchPluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function
SearchPluginBase::$keywords protected property The keywords to use in a search.
SearchPluginBase::$searchAttributes protected property Array of attributes - usually from the request object.
SearchPluginBase::$searchParameters protected property Array of parameters from the query string from the request.
SearchPluginBase::buildResults public function Executes the search and builds render arrays for the result items. Overrides SearchInterface::buildResults 1
SearchPluginBase::getAttributes public function Returns the currently set attributes (from the request). Overrides SearchInterface::getAttributes
SearchPluginBase::getHelp public function Returns the searching help. Overrides SearchInterface::getHelp 1
SearchPluginBase::getKeywords public function Returns the currently set keywords of the plugin instance. Overrides SearchInterface::getKeywords
SearchPluginBase::getParameters public function Returns the current parameters set using setSearch(). Overrides SearchInterface::getParameters
SearchPluginBase::setSearch public function Sets the keywords, parameters, and attributes to be used by execute(). Overrides SearchInterface::setSearch 1
SearchPluginBase::suggestedTitle public function Provides a suggested title for a page of search results. Overrides SearchInterface::suggestedTitle
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.