You are here

function eva_view_presave in EVA: Entity Views Attachment 8

Same name and namespace in other branches
  1. 8.2 eva.module \eva_view_presave()

Implements hook_ENTITY_TYPE_presave(). Address https://www.drupal.org/node/2922112: if Eva displays are removed, remove the module dependency from the View

File

./eva.module, line 205
Module implementing EVA extra field and views display

Code

function eva_view_presave(EntityInterface $view) {
  $dependencies = $view
    ->get('dependencies');
  if (in_array('eva', $dependencies['module'])) {
    $eva_count = 0;
    foreach ($view
      ->get('display') as $display_id => $display) {

      // is there a display that's still using Eva?
      if ($display['display_plugin'] == 'entity_view') {
        $eva_count += 1;
      }
    }

    // no Eva's? Remove the dependency
    if ($eva_count == 0) {
      $dependencies['module'] = array_values(array_diff($dependencies['module'], [
        'eva',
      ]));
      $view
        ->set('dependencies', $dependencies);
    }
  }
}