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

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

(cherry picked from commit 2b90522e)
parent 3f6bec74
No related branches found
No related tags found
23 merge requests!11958Issue #3490507 by alexpott, smustgrave: Fix bogus mocking in...,!11769Issue #3517987: Add option to contextual filters to encode slashes in query parameter.,!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #159828 canceled
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
...@@ -12,9 +14,22 @@ core.menu.static_menu_link_overrides: ...@@ -12,9 +14,22 @@ 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,7 +139,10 @@ public function saveOverride($id, array $definition) { ...@@ -139,7 +139,10 @@ 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'];
$definition['parent'] = (string) $definition['parent']; // Map `''` to `NULL`. The inverse operation is handled by the menu link manager.
// @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: '' parent: null
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: '' parent: null
weight: 0 weight: 0
expanded: false expanded: false
enabled: true enabled: true
  • catch @catch

    mentioned in commit 895d0e29

    ·

    mentioned in commit 895d0e29

    Toggle commit list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment