You are here

public function LiveResults::calculateDependencies in Search API Autocomplete 8

Calculates dependencies for the configured plugin.

Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.

Return value

array An array of dependencies grouped by type (config, content, module, theme). For example:

array(
  'config' => array(
    'user.role.anonymous',
    'user.role.authenticated',
  ),
  'content' => array(
    'node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d',
  ),
  'module' => array(
    'node',
    'user',
  ),
  'theme' => array(
    'seven',
  ),
);

Overrides ConfigurablePluginBase::calculateDependencies

See also

\Drupal\Core\Config\Entity\ConfigDependencyManager

\Drupal\Core\Entity\EntityInterface::getConfigDependencyName()

File

src/Plugin/search_api_autocomplete/suggester/LiveResults.php, line 388

Class

LiveResults
Provides a suggester plugin that displays live results.

Namespace

Drupal\search_api_autocomplete\Plugin\search_api_autocomplete\suggester

Code

public function calculateDependencies() {
  $this->dependencies = parent::calculateDependencies();
  $index = $this
    ->getSearch()
    ->getIndex();
  foreach ($this->configuration['view_modes'] as $datasource_id => $bundles) {
    $datasource = $index
      ->getDatasource($datasource_id);
    $entity_type_id = $datasource
      ->getEntityTypeId();

    // If the datasource doesn't represent an entity type, we unfortunately
    // can't know what dependencies its view modes might have.
    if (!$entity_type_id) {
      continue;
    }
    foreach ($bundles as $bundle => $view_mode) {
      if ($view_mode === '') {
        continue;
      }

      /** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode_entity */
      $view_mode_entity = $this
        ->getEntityTypeManager()
        ->getStorage('entity_view_mode')
        ->load($entity_type_id . '.' . $view_mode);
      if ($view_mode_entity) {
        $key = $view_mode_entity
          ->getConfigDependencyKey();
        $name = $view_mode_entity
          ->getConfigDependencyName();
        $this
          ->addDependency($key, $name);
      }
    }
  }
  return $this->dependencies;
}