Skip to content
Snippets Groups Projects
Commit 993ba290 authored by Ivan Doroshenko's avatar Ivan Doroshenko
Browse files

Issue #3369030 by Matroskeen: Remove rabbit_hole.behavior_settings.default config

parent 4e8e0974
No related branches found
No related tags found
2 merge requests!68Issue #3298741: Fix the issues reported by phpcs,!55Issue #3369030 by Matroskeen: Remove rabbit_hole.behavior_settings.default config.
id: default
entity_type_id : null
entity_id : null
action: "display_page"
configuration: { }
......@@ -335,3 +335,12 @@ function rabbit_hole_update_8108() {
$config->save();
}
}
/**
* Remove useless "rabbit_hole.behavior_settings.default" config.
*/
function rabbit_hole_update_8109() {
\Drupal::configFactory()
->getEditable('rabbit_hole.behavior_settings.default')
->delete();
}
......@@ -110,13 +110,20 @@ class BehaviorSettingsManager implements BehaviorSettingsManagerInterface {
$entity_type = $this->entityTypeManager->getStorage($entity_type_id)->getEntityType();
$bundle_entity_type = $entity_type->getBundleEntityType();
if ($bundle_entity_type) {
$config = $this->loadBehaviorSettingsAsConfig($bundle_entity_type, $bundle);
}
else {
$config = $this->loadBehaviorSettingsAsConfig($entity_type_id);
$config_id = $this->generateBehaviorSettingsFullId($bundle_entity_type, $bundle);
$actual = $this->configFactory->get("rabbit_hole.behavior_settings.{$config_id}");
if (!$actual->isNew()) {
return $actual->get();
}
return $config->get();
// @todo Remove usage of default config in 3.0.
// Also, there shouldn't be a need for default configuration in the next
// version. If configuration is not available, it should be simply ignored.
$default = $this->configFactory->get('rabbit_hole.behavior_settings.default');
return !$default->isNew() ? $default->get() : [
'action' => 'display_page',
'configuration' => [],
];
}
/**
......@@ -150,34 +157,10 @@ class BehaviorSettingsManager implements BehaviorSettingsManagerInterface {
return $values;
}
/**
* Loads a config with default settings.
*
* @todo What if the config was manually removed? We should get rid of it and
* keep the defaults somewhere else.
*/
public function loadDefaultConfig() {
return $this->configFactory->get('rabbit_hole.behavior_settings.default');
}
/**
* Loads config object for the given entity type and bundle.
*/
protected function loadBehaviorSettingsAsConfig(string $entity_type_id, ?string $entity_id = NULL) {
$config_id = $this->generateBehaviorSettingsFullId($entity_type_id, $entity_id);
$actual = $this->configFactory->get("rabbit_hole.behavior_settings.{$config_id}");
if (!$actual->isNew()) {
return $actual;
}
else {
return $this->loadDefaultConfig();
}
}
/**
* Generate a full ID based on entity type label, bundle label and entity id.
*
* @param string $entity_type_id
* @param string|null $entity_type_id
* The entity type (e.g. node) as a string.
* @param string|null $entity_id
* The entity ID as a string.
......@@ -185,8 +168,11 @@ class BehaviorSettingsManager implements BehaviorSettingsManagerInterface {
* @return string
* The full id appropriate for a BehaviorSettings config entity.
*/
protected function generateBehaviorSettingsFullId(string $entity_type_id, ?string $entity_id = NULL): string {
return $entity_type_id . (isset($entity_id) ? '_' . $entity_id : '');
protected function generateBehaviorSettingsFullId(?string $entity_type_id, ?string $entity_id = NULL): string {
if ($entity_type_id) {
return $entity_type_id . (isset($entity_id) ? '_' . $entity_id : '');
}
return $entity_id;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment