protected function Index::getDependencyData in Search API 8
Retrieves data about this index's dependencies.
The return value is structured as follows:
[
'config' => [
'CONFIG_DEPENDENCY_KEY' => [
'always' => [
'processors' => [
'PROCESSOR_ID' => $processor,
],
'datasources' => [
'DATASOURCE_ID_1' => $datasource_1,
'DATASOURCE_ID_2' => $datasource_2,
],
],
'optional' => [
'index' => [
'INDEX_ID' => $index,
],
'tracker' => [
'TRACKER_ID' => $tracker,
],
],
],
],
];
Enforced dependencies are not included in this method's return value.
Return value
object[][][][][] An associative array containing the index'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 index 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 index) in question or potentially depending on the configuration. The values on this level are arrays with keys "index", "tracker", "datasources" and/or "processors" and values arrays of IDs mapped to their entities/plugins.
2 calls to Index::getDependencyData()
- Index::calculateDependencies in src/
Entity/ Index.php - Calculates dependencies and stores them in the dependency property.
- Index::onDependencyRemoval in src/
Entity/ Index.php - Informs the entity that entities it depends on will be deleted.
File
- src/
Entity/ Index.php, line 1673
Class
- Index
- Defines the search index configuration entity.
Namespace
Drupal\search_api\EntityCode
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']['index'][$this->id] = $this;
}
}
$this->dependencies = $original_dependencies;
// Include the field dependencies.
$type_dependencies = [];
foreach ($this
->getFields() as $field_id => $field) {
foreach ($field
->getDependencies() as $dependency_type => $names) {
foreach ($names as $name) {
$dependency_data[$dependency_type][$name]['always']['fields'][$field_id] = $field;
}
}
// Also take dependencies of the field's data type plugin into account.
// (Since data type plugins cannot have configuration, this will always be
// the same for a certain type, so we only have to compute this once per
// type.)
$type = $field
->getType();
if (!isset($type_dependencies[$type])) {
$type_dependencies[$type] = [];
$data_type = $field
->getDataTypePlugin();
if ($data_type && !$data_type
->isDefault()) {
$definition = $data_type
->getPluginDefinition();
$type_dependencies[$type]['module'][] = $definition['provider'];
// Plugins can declare additional dependencies in their definition.
if (!empty($definition['config_dependencies'])) {
$type_dependencies[$type] = NestedArray::mergeDeep($type_dependencies[$type], $definition['config_dependencies']);
}
// If a plugin is dependent, calculate its dependencies.
if ($data_type instanceof DependentPluginInterface) {
$type_dependencies[$type] = NestedArray::mergeDeep($type_dependencies[$type], $data_type
->calculateDependencies());
}
}
}
foreach ($type_dependencies[$type] as $dependency_type => $list) {
foreach ($list as $name) {
$dependency_data[$dependency_type][$name]['optional']['fields'][$field_id] = $field;
}
}
}
// The server needs special treatment, since it is a dependency of the index
// itself, and not one of its plugins.
if ($this
->hasValidServer()) {
$name = $this
->getServerInstance()
->getConfigDependencyName();
$dependency_data['config'][$name]['optional']['index'][$this->id] = $this;
}
// All other plugins can be treated uniformly.
$plugins = $this
->getAllPlugins();
foreach ($plugins as $plugin_type => $type_plugins) {
foreach ($type_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'][$plugin_type][$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'][$plugin_type][$plugin_id] = $plugin;
}
}
}
// Finally, 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'][$plugin_type][$plugin_id] = $plugin;
}
}
}
}
return $dependency_data;
}