Commit bedbaf72 authored by catch's avatar catch

Issue #3006815 by plach, gmaka, mudassar774, amateescu, Lendude:...

Issue #3006815 by plach, gmaka, mudassar774, amateescu, Lendude: ViewsEntitySchemaSubscriber may fail when a view has a broken handler
parent ed71ff55
......@@ -306,7 +306,7 @@ protected function baseTableRename($all_views, $entity_type_id, $old_base_table,
}
}
$this->processHandlers($all_views, function (array &$handler_config, ViewEntityInterface $view) use ($entity_type_id, $old_base_table, $new_base_table) {
$this->processHandlers($all_views, function (&$handler_config, ViewEntityInterface $view) use ($entity_type_id, $old_base_table, $new_base_table) {
if (isset($handler_config['entity_type']) && $handler_config['entity_type'] == $entity_type_id && $handler_config['table'] == $old_base_table) {
$handler_config['table'] = $new_base_table;
$view->set('_updated', TRUE);
......@@ -334,7 +334,7 @@ protected function dataTableRename($all_views, $entity_type_id, $old_data_table,
}
}
$this->processHandlers($all_views, function (array &$handler_config, ViewEntityInterface $view) use ($entity_type_id, $old_data_table, $new_data_table) {
$this->processHandlers($all_views, function (&$handler_config, ViewEntityInterface $view) use ($entity_type_id, $old_data_table, $new_data_table) {
if (isset($handler_config['entity_type']) && $handler_config['entity_type'] == $entity_type_id && $handler_config['table'] == $old_data_table) {
$handler_config['table'] = $new_data_table;
$view->set('_updated', TRUE);
......@@ -365,7 +365,7 @@ protected function dataTableAddition($all_views, EntityTypeInterface $entity_typ
$data_table = $new_data_table;
$this->processHandlers($all_views, function (array &$handler_config, ViewEntityInterface $view) use ($entity_type_id, $base_table, $data_table, $base_table_fields, $data_table_fields) {
$this->processHandlers($all_views, function (&$handler_config, ViewEntityInterface $view) use ($entity_type_id, $base_table, $data_table, $base_table_fields, $data_table_fields) {
if (isset($handler_config['entity_type']) && isset($handler_config['entity_field']) && $handler_config['entity_type'] == $entity_type_id) {
// Move all fields which just exists on the data table.
if ($handler_config['table'] == $base_table && in_array($handler_config['entity_field'], $data_table_fields) && !in_array($handler_config['entity_field'], $base_table_fields)) {
......@@ -390,7 +390,7 @@ protected function dataTableAddition($all_views, EntityTypeInterface $entity_typ
*/
protected function dataTableRemoval($all_views, $entity_type_id, $old_data_table, $base_table) {
// We move back the data table back to the base table.
$this->processHandlers($all_views, function (array &$handler_config, ViewEntityInterface $view) use ($entity_type_id, $old_data_table, $base_table) {
$this->processHandlers($all_views, function (&$handler_config, ViewEntityInterface $view) use ($entity_type_id, $old_data_table, $base_table) {
if (isset($handler_config['entity_type']) && $handler_config['entity_type'] == $entity_type_id) {
if ($handler_config['table'] == $old_data_table) {
$handler_config['table'] = $base_table;
......
<?php
/**
* @file
* Contains the "views_test_config" module main functionality.
*/
/**
* Implements hook_ENTITY_TYPE_load().
*/
function views_test_config_view_load(array $views) {
// Emulate a severely broken view: this kind of view configuration cannot be
// saved, it can likely be returned only by a corrupt active configuration.
$broken_view_id = \Drupal::state()->get('views_test_config.broken_view');
if (isset($views[$broken_view_id])) {
$display =& $views[$broken_view_id]->getDisplay('default');
$display['display_options']['fields']['id_broken'] = NULL;
}
}
......@@ -501,6 +501,25 @@ public function testViewSaveException() {
]);
}
/**
* Tests that broken views are handled gracefully.
*/
public function testBrokenView() {
$view_id = 'test_view_entity_test';
$this->state->set('views_test_config.broken_view', $view_id);
$this->updateEntityTypeToTranslatable(TRUE);
/** @var \Drupal\views\Entity\View $view */
$entity_storage = $this->entityTypeManager->getStorage('view');
$view = $entity_storage->load($view_id);
// The broken handler should have been removed.
$display = $view->getDisplay('default');
$this->assertFalse(isset($display['display_options']['fields']['id_broken']));
$this->assertUpdatedViews([$view_id]);
}
/**
* Gets a view and its display.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment