function _eva_clear_detached in EVA: Entity Views Attachment 8
An extra field no longer present is not automatically removed from a display config Run through all entity displays and clear out views that shouldn't be there this should be called at Views save and module install/remove $remove_one: force removal of a particular 'viewname_displayid' EVA $remove_all: remove all Evas
3 calls to _eva_clear_detached()
- Eva::remove in src/
Plugin/ views/ display/ Eva.php - Reacts on deleting a display.
- eva_views_invalidate_cache in ./
eva.module - Clear the field cache when view cache clears this is intended to fire when a View is saved
- _eva_reset in ./
eva.module - Cache clearing helper function Reset the static cache in case any of the disabled modules implemented an eva view
File
- ./
eva.module, line 241 - Module implementing EVA extra field and views display
Code
function _eva_clear_detached($remove_one = null, $remove_all = FALSE) {
$cf = \Drupal::configFactory();
$views = eva_get_views();
foreach ($views as $entity => $eva_info) {
$config_names = $cf
->listAll('core.entity_view_display.' . $entity);
foreach ($config_names as $id) {
$config = $cf
->getEditable($id);
$config_data = $config
->get();
foreach ($eva_info as $eva) {
$eva_field_name = $eva['name'] . '_' . $eva['display'];
// eva should be considered for removal if one of these is true:
// - all evas should be removed (i.e., when module is uninstalled)
// - the current eva has at least on bundle specified (if no bundles are specified, an eva is attached to all bundles)
// - the current eva is specifically targeted for removal (i.e., before deleting the display)
if ($remove_all || !empty($eva['bundles']) || $eva_field_name == $remove_one) {
// does the eva exist in this display config?
if (array_key_exists($eva_field_name, $config_data['content'])) {
// remove the eva if one of these is true:
// - all evas should be removed
// - the eva does not list the entity's bundle (any more)
// - the eva is specifically targeted for removal
if ($remove_all || !in_array($config_data['bundle'], $eva['bundles']) || $eva_field_name == $remove_one) {
unset($config_data['content'][$eva_field_name]);
// exposed filter, too, if it's there
unset($config_data['content'][$eva_field_name . '_form']);
$config
->setData($config_data);
$config
->save();
}
}
}
}
}
}
}