function View::onDependencyRemoval

Same name and namespace in other branches
  1. 9 core/modules/views/src/Entity/View.php \Drupal\views\Entity\View::onDependencyRemoval()
  2. 8.9.x core/modules/views/src/Entity/View.php \Drupal\views\Entity\View::onDependencyRemoval()
  3. 11.x core/modules/views/src/Entity/View.php \Drupal\views\Entity\View::onDependencyRemoval()

Overrides ConfigEntityBase::onDependencyRemoval

File

core/modules/views/src/Entity/View.php, line 483

Class

View
Defines a View configuration entity class.

Namespace

Drupal\views\Entity

Code

public function onDependencyRemoval(array $dependencies) {
  $changed = FALSE;
  // Don't intervene if the views module is removed.
  if (isset($dependencies['module']) && in_array('views', $dependencies['module'])) {
    return FALSE;
  }
  // If the base table for the View is provided by a module being removed, we
  // delete the View because this is not something that can be fixed manually.
  $views_data = Views::viewsData();
  $base_table = $this->get('base_table');
  $base_table_data = $views_data->get($base_table);
  if (!empty($base_table_data['table']['provider']) && in_array($base_table_data['table']['provider'], $dependencies['module'])) {
    return FALSE;
  }
  $current_display = $this->getExecutable()->current_display;
  $handler_types = Views::getHandlerTypes();
  // Find all the handlers and check whether they want to do something on
  // dependency removal.
  foreach ($this->display as $display_id => $display_plugin_base) {
    $this->getExecutable()
      ->setDisplay($display_id);
    $display = $this->getExecutable()
      ->getDisplay();
    foreach (array_keys($handler_types) as $handler_type) {
      $handlers = $display->getHandlers($handler_type);
      foreach ($handlers as $handler_id => $handler) {
        if ($handler instanceof DependentWithRemovalPluginInterface) {
          if ($handler->onDependencyRemoval($dependencies)) {
            // Remove the handler and indicate we made changes.
            unset($this->display[$display_id]['display_options'][$handler_types[$handler_type]['plural']][$handler_id]);
            $changed = TRUE;
          }
        }
      }
    }
  }
  // Disable the View if we made changes.
  // @todo https://www.drupal.org/node/2832558 Give better feedback for
  // disabled config.
  if ($changed) {
    // Force a recalculation of the dependencies if we made changes.
    $this->getExecutable()->current_display = NULL;
    $this->calculateDependencies();
    $this->disable();
  }
  $this->getExecutable()
    ->setDisplay($current_display);
  return $changed;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.