You are here

protected function SavedSearchType::getDependencyData in Search API Saved Searches 8

Retrieves data about this type's dependencies.

The return value is structured as follows:

[
  'config' => [
    'CONFIG_DEPENDENCY_KEY' => [
      'always' => [
        'entity' => [
          'TYPE_ID' => $type,
        ],
        'notification' => [
          'NOTIFICATION_ID' => $notification_plugin,
        ],
      ],
      'optional' => [
        'notification' => [
          'NOTIFICATION_ID' => $notification_plugin,
        ],
      ],
    ],
  ],
];

Enforced dependencies are not included in this method's return value.

Return value

object[][][][][] An associative array containing the type's dependencies. The array is first keyed by the config dependency type ("module", "config", etc.) and then by the names of the config dependencies of that type which the entity has. The values are associative arrays with up to two keys, "always" and "optional", specifying whether the dependency is a hard one by the plugin (or entity) in question or potentially depending on the configuration. The values on this level are arrays with keys "entity" and/or "notification" and values arrays of IDs mapped to their entities/plugins.

2 calls to SavedSearchType::getDependencyData()
SavedSearchType::calculateDependencies in src/Entity/SavedSearchType.php
Calculates dependencies and stores them in the dependency property.
SavedSearchType::onDependencyRemoval in src/Entity/SavedSearchType.php
Informs the entity that entities it depends on will be deleted.

File

src/Entity/SavedSearchType.php, line 616

Class

SavedSearchType
Provides an entity type for configuring how searches can be saved.

Namespace

Drupal\search_api_saved_searches\Entity

Code

protected function getDependencyData() {
  $dependency_data = [];

  // Since calculateDependencies() will work directly on the $dependencies
  // property, we first save its original state and then restore it
  // afterwards.
  $original_dependencies = $this->dependencies;
  parent::calculateDependencies();
  unset($this->dependencies['enforced']);
  foreach ($this->dependencies as $dependency_type => $list) {
    foreach ($list as $name) {
      $dependency_data[$dependency_type][$name]['always']['entity'][$this->id] = $this;
    }
  }
  $this->dependencies = $original_dependencies;

  // In theory, we also depend on all existing indexes (since we store their
  // IDs in $this->options['date_field']) and all search displays (in
  // $this->options['displays']). However, since having unknown plugin/entity
  // IDs there doesn't really cause any problems, we don't include them as
  // optional dependencies here.
  $plugins = $this
    ->getNotificationPlugins();
  foreach ($plugins as $plugin_id => $plugin) {

    // Largely copied from
    // \Drupal\Core\Plugin\PluginDependencyTrait::calculatePluginDependencies().
    $definition = $plugin
      ->getPluginDefinition();

    // First, always depend on the module providing the plugin.
    $dependency_data['module'][$definition['provider']]['always']['notification'][$plugin_id] = $plugin;

    // Plugins can declare additional dependencies in their definition.
    if (isset($definition['config_dependencies'])) {
      foreach ($definition['config_dependencies'] as $dependency_type => $list) {
        foreach ($list as $name) {
          $dependency_data[$dependency_type][$name]['always']['notification'][$plugin_id] = $plugin;
        }
      }
    }

    // Then, add the dynamically-calculated dependencies of the plugin.
    foreach ($plugin
      ->calculateDependencies() as $dependency_type => $list) {
      foreach ($list as $name) {
        $dependency_data[$dependency_type][$name]['optional']['notification'][$plugin_id] = $plugin;
      }
    }
  }
  return $dependency_data;
}