We have a similar problem but the hook is block_class_update_20017()
We have an additional issue where we run feature:import before database updates.
The feature:import adds additional classes in via:
```
third_party_settings:
block_class:
classes: my-class-1
```
We end up with block_classes.settings in the database that looks like:
```
block_classes_stored [
'my-class-1',
'{my-class-2:my-class-2, my-class-3:my-class-3}',
'my-class-4',
];
```
This is my solution that can convert our situation into a proper array of block classes for block_class.settings.yml:
```
/**
* Convert block_classes_stored from JSON to a sequence.
*/
function block_class_update_20017() {
$config = \Drupal::configFactory()->getEditable('block_class.settings');
$new_classes = [];
$block_classes_stored = $config->get('block_classes_stored');
foreach ($block_classes_stored as $block_classes) {
if (is_string($block_classes)) {
$decoded = Json::decode($block_classes);
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
// Json decoded successfully with no errors. Add it to the classes.
$new_classes = array_merge($new_classes, $decoded);
}
else {
// We have a string... but it's not a JSON encoded string. Add it to the classes.
$new_classes[] = $block_classes;
}
}
}
$new_classes = array_unique(array_filter(array_values($new_classes)));
$config->set('block_classes_stored', $new_classes);
$config->save();
}
```
Patch #19 won't apply to 10.4.4 so I did it manually.
```
diff --git a/modules/update/src/Routing/UpdateRouteSubscriber.php b/modules/update/src/Routing/UpdateRouteSubscriber.php
index 57ff5f4561..9bffe435f0 100644
--- a/modules/update/src/Routing/UpdateRouteSubscriber.php
+++ b/modules/update/src/Routing/UpdateRouteSubscriber.php
@@ -29,8 +29,11 @@ protected function alterRoutes(RouteCollection $collection) {
return;
}
$routes = [
+ 'update.report_install',
'update.report_update',
+ 'update.module_install',
'update.module_update',
+ 'update.theme_install',
'update.theme_update',
'update.confirmation_page',
];
```
merlin06 → changed the visibility of the branch 2.0.0 to hidden.
Our codebase currently doesn't use the same code quality checks as per git.drupalcode.org so any suggestions I make are pretty much useless right now.
merlin06 → created an issue.
This patch restores the original else branch that is still required.
else {
$views_data = $this->getViewsData()->get($this->view->storage->get('base_table'));
}
Patch 12 is incorrect.
Rolled patch 13 against original file.
Rolled a patch.
Credit for this snippet goes to https://www.drupal.org/u/bradtreloar → from https://www.drupal.org/australian-competition-and-consumer-commission-accc → and I modified the issue description with it.
$relationships = $this->displayHandler->getOption('relationships');
if(isset($relationships[$this->options['relationship']])) {
$relationship = $relationships[$this->options['relationship']];
$table_data = $this->getViewsData()->get($relationship['table']);
$views_data = $this->getViewsData()->get($table_data[$relationship['field']]['relationship']['base']);
}
else {
$views_data = $this->getViewsData()->get($this->view->storage->get('base_table'));
}
Preserving the original code
/**
* {@inheritdoc}
*/
public function getEntityType() {
// If the user has configured a relationship on the handler take that into
// account.
if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') {
$relationships = $this->displayHandler->getOption('relationships');
if(isset($relationships[$this->options['relationship']])) {
$relationship = $relationships[$this->options['relationship']];
$table_data = $this->getViewsData()->get($relationship['table']);
$views_data = $this->getViewsData()->get($table_data[$relationship['field']]['relationship']['base']);
}
else {
$views_data = $this->getViewsData()->get($this->view->storage->get('base_table'));
}
}
else {
$views_data = $this->getViewsData()->get($this->view->storage->get('base_table'));
}
if (isset($views_data['table']['entity type'])) {
return $views_data['table']['entity type'];
}
else {
throw new \Exception("No entity type for field {$this->options['id']} on view {$this->view->storage->id()}");
}
}
merlin06 → created an issue.