public function RenderedItem::onDependencyRemoval in Search API 8
Informs the plugin that some of its dependencies are being removed.
The plugin should attempt to change its configuration in a way to remove its dependency on those items. However, to avoid problems, it should (as far as possible) not add any new dependencies in the process, since there is no guarantee that those are not currently being removed, too.
Parameters
object[][] $dependencies: An array of dependencies, keyed by dependency type ("module", "config", etc.) and dependency name.
Return value
bool Whether the dependency was successfully removed from the plugin – that is, after the configuration changes that were made, none of the removed items are dependencies of this plugin anymore.
Overrides ConfigurablePluginBase::onDependencyRemoval
File
- src/
Plugin/ search_api/ processor/ RenderedItem.php, line 349
Class
- RenderedItem
- Adds an additional field containing the rendered item.
Namespace
Drupal\search_api\Plugin\search_api\processorCode
public function onDependencyRemoval(array $dependencies) {
// All dependencies of this processor are entity view modes, so we go
// through all of the index's fields using our property and remove the
// settings for all datasources or bundles which were set to one of the
// removed view modes. This will always result in the removal of all those
// dependencies.
// The code is highly similar to calculateDependencies(), only that we
// remove the setting (if necessary) instead of adding a dependency.
$fields = $this
->getFieldsHelper()
->filterForPropertyPath($this->index
->getFields(), NULL, 'rendered_item');
foreach ($fields as $field) {
$field_config = $field
->getConfiguration();
$view_modes = $field_config['view_mode'];
foreach ($this->index
->getDatasources() as $datasource_id => $datasource) {
$entity_type_id = $datasource
->getEntityTypeId();
if (!$entity_type_id) {
continue;
}
foreach ($view_modes[$datasource_id] ?? [] as $bundle => $view_mode_id) {
if ($view_mode_id) {
/** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode */
$view_mode = EntityViewMode::load($entity_type_id . '.' . $view_mode_id);
if ($view_mode) {
$dependency_key = $view_mode
->getConfigDependencyKey();
$dependency_name = $view_mode
->getConfigDependencyName();
if (!empty($dependencies[$dependency_key][$dependency_name])) {
unset($view_modes[$datasource_id][$bundle]);
}
}
}
}
}
$field_config['view_mode'] = $view_modes;
$field
->setConfiguration($field_config);
}
return TRUE;
}