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

Revert "Issue #3441434 by narendraR, Wim Leers: Add validation constraints to core.menu.schema.yml"

This reverts commit 2b90522e.
parent 2b90522e
No related branches found
No related tags found
No related merge requests found
core.menu.static_menu_link_overrides: core.menu.static_menu_link_overrides:
type: config_object type: config_object
label: 'Static menu link overrides' label: 'Static menu link overrides'
constraints:
FullyValidatable: ~
mapping: mapping:
definitions: definitions:
type: sequence type: sequence
...@@ -14,22 +12,9 @@ core.menu.static_menu_link_overrides: ...@@ -14,22 +12,9 @@ core.menu.static_menu_link_overrides:
menu_name: menu_name:
type: string type: string
label: 'Menu name' label: 'Menu name'
# This is the id of system.menu.* config.
# @see core/modules/system/config/schema/system.schema.yml
ConfigExists:
prefix: 'system.menu.'
parent: parent:
type: string type: string
label: 'Parent' label: 'Parent'
# Menu link plugins specify the empty string if there is no parent. But the empty string is not a valid menu
# link plugin ID. In this config representation, "no parent" is therefore represented as `null`, not `''`.
# @see \Drupal\Core\Menu\MenuLinkInterface::getParent()
# @see \Drupal\Core\Menu\StaticMenuLinkOverrides::saveOverride()
nullable: true
constraints:
PluginExists:
manager: plugin.manager.menu.link
interface: 'Drupal\Core\Menu\MenuLinkInterface'
weight: weight:
type: weight type: weight
label: 'Weight' label: 'Weight'
......
...@@ -139,10 +139,7 @@ public function saveOverride($id, array $definition) { ...@@ -139,10 +139,7 @@ public function saveOverride($id, array $definition) {
if ($definition) { if ($definition) {
// Cast keys to avoid config schema during save. // Cast keys to avoid config schema during save.
$definition['menu_name'] = (string) $definition['menu_name']; $definition['menu_name'] = (string) $definition['menu_name'];
// Map `''` to `NULL`. The inverse operation is handled by the menu link manager. $definition['parent'] = (string) $definition['parent'];
// @see core/config/schema/core.menu.schema.yml
// @see \Drupal\Core\Menu\MenuLinkManager::processDefinition()
$definition['parent'] = empty($definition['parent']) ? NULL : (string) $definition['parent'];
$definition['weight'] = (int) $definition['weight']; $definition['weight'] = (int) $definition['weight'];
$definition['expanded'] = (bool) $definition['expanded']; $definition['expanded'] = (bool) $definition['expanded'];
$definition['enabled'] = (bool) $definition['enabled']; $definition['enabled'] = (bool) $definition['enabled'];
......
<?php
/**
* @file
* Post update functions for config.
*/
/**
* Fix core.menu.static_menu_link_overrides:definitions.*.parent value to null.
*/
function config_post_update_set_menu_parent_value_to_null(): void {
$config = \Drupal::configFactory()->getEditable('core.menu.static_menu_link_overrides');
$all_overrides = $config->get('definitions') ?: [];
foreach ($all_overrides as $definition_key => $definition_value) {
if ($definition_value['parent'] === '') {
$config->set('definitions.' . $definition_key . '.parent', NULL)->save();
}
}
}
<?php
declare(strict_types=1);
namespace Drupal\Tests\config\Functional\Update;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
/**
* Tests update of core.menu.static_menu_link_overrides:definitions.*.parent.
*
* @group config
* @covers \config_post_update_set_menu_parent_value_to_null
*/
class UpdateMenuParentUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-10.3.0.bare.standard.php.gz',
];
}
/**
* Tests update of core.menu.static_menu_link_overrides:definitions.*.parent.
*/
public function testUpdate(): void {
$this->assertNotNull($this->config('core.menu.static_menu_link_overrides')->get('definitions.contact__site_page.parent'));
$this->runUpdates();
$this->assertNull($this->config('core.menu.static_menu_link_overrides')->get('definitions.contact__site_page.parent'));
}
}
definitions: definitions:
contact__site_page: contact__site_page:
menu_name: footer menu_name: footer
parent: null parent: ''
weight: 0 weight: 0
expanded: false expanded: false
enabled: true enabled: true
definitions: definitions:
contact__site_page: contact__site_page:
menu_name: footer menu_name: footer
parent: null parent: ''
weight: 0 weight: 0
expanded: false expanded: false
enabled: true enabled: true
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