Skip to content
Snippets Groups Projects
Commit d9e654e5 authored by catch's avatar catch
Browse files

Issue #3295813 by andypost, Berdir: ViewsEntitySchemaSubscriber access undefined property of View

(cherry picked from commit 6af21dee)
parent c6f17378
No related branches found
No related tags found
24 merge requests!8506Draft: Issue #3456536 by ibrahim tameme,!5646Issue #3350972 by nod_: [random test failure]...,!5600Issue #3350972 by nod_: [random test failure]...,!5343Issue #3305066 by quietone, Rename RedirectLeadingSlashesSubscriber,!4350Issue #3307718: Implement xxHash for non-cryptographic use-cases,!3603#ISSUE 3346218 Add a different message on edit comment,!3555Issue #2473873: Views entity operations lack cacheability support, resulting in incorrect dropbuttons,!3494Issue #3327018 by Spokje, longwave, xjm, mondrake: Update PHPStan to 1.9.3 and...,!3410Issue #3340128: UserLoginForm::submitForm has some dead code,!3389Issue #3325184 by Spokje, andypost, xjm, smustgrave: $this->configFactory is...,!3381Issue #3332363: Refactor Claro's menus-and-lists stylesheet,!3307Issue #3326193: CKEditor 5 can grow past the viewport when there is a lot of content,!3236Issue #3332419: Refactor Claro's messages stylesheet,!3231Draft: Issue #3049525 by longwave, fougere, larowlan, kim.pepper, AaronBauman, Wim...,!3212Issue #3294003: Refactor Claro's entity-meta stylesheet,!3194Issue #3330981: Fix PHPStan L1 error "Relying on entity queries to check access by default is deprecated...",!3143Issue #3313342: [PHP 8.1] Deprecated function: strpos(): Passing null to parameter #1 LayoutBuilderUiCacheContext.php on line 28,!3024Issue #3307509: Empty option for views bulk form,!2972Issue #1845004: Replace custom password hashing library with PHP 5.5 password_hash(),!2719Issue #3110137: Remove Classy from core.,!2688Issue #3261452: [PP-1] Remove tracker module from core,!2437Issue #3238257 by hooroomoo, Wim Leers: Fragment link pointing to <textarea>...,!2296Issue #3100732: Allow specifying `meta` data on JSON:API objects,!1626Issue #3256642: Make life better for database drivers that extend another database driver
......@@ -83,6 +83,13 @@ class ViewsEntitySchemaSubscriber implements EntityTypeListenerInterface, EventS
*/
protected $logger;
/**
* Array of views that need to be saved, indexed by view name.
*
* @var \Drupal\views\ViewEntityInterface[]
*/
protected $viewsToSave = [];
/**
* Constructs a ViewsEntitySchemaSubscriber.
*
......@@ -208,17 +215,12 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI
}
}
// Filter the list of views that needs to be updated.
$views_to_update = array_filter($all_views, function (ViewEntityInterface $view) {
return $view->get('_updated') === TRUE;
});
foreach ($views_to_update as $view) {
foreach ($this->viewsToSave as $view) {
try {
// All changes done to the views here can be trusted and this might be
// called during updates, when it is not safe to rely on configuration
// containing valid schema. Trust the data and disable schema validation
// and casting.
$view->set('_updated', NULL);
$view->trustData()->save();
}
catch (\Exception $e) {
......@@ -231,6 +233,7 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI
]);
}
}
$this->viewsToSave = [];
}
/**
......@@ -300,14 +303,14 @@ protected function baseTableRename($all_views, $entity_type_id, $old_base_table,
foreach ($all_views as $view) {
if ($view->get('base_table') == $old_base_table) {
$view->set('base_table', $new_base_table);
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
}
$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);
$this->viewsToSave[$view->id()] = $view;
}
});
}
......@@ -328,14 +331,14 @@ protected function dataTableRename($all_views, $entity_type_id, $old_data_table,
foreach ($all_views as $view) {
if ($view->get('base_table') == $old_data_table) {
$view->set('base_table', $new_data_table);
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
}
$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);
$this->viewsToSave[$view->id()] = $view;
}
});
}
......@@ -368,7 +371,7 @@ protected function dataTableAddition($all_views, EntityTypeInterface $entity_typ
// 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)) {
$handler_config['table'] = $data_table;
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
}
});
......@@ -392,7 +395,7 @@ protected function dataTableRemoval($all_views, $entity_type_id, $old_data_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;
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
}
});
......@@ -414,7 +417,7 @@ protected function revisionRemoval($all_views, EntityTypeInterface $original) {
if (in_array($view->get('base_table'), [$revision_base_table, $revision_data_table])) {
// Let's disable the views as we no longer support revisions.
$view->setStatus(FALSE);
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
// For any kind of field, let's rely on the broken handler functionality.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment