diff --git a/core/modules/navigation/config/install/navigation.settings.yml b/core/modules/navigation/config/install/navigation.settings.yml index 272eddb470976a835bb9c8ced03c3dbff2860a52..ffa4ff79c88d111c47443bc2d9866f7f551f57ea 100644 --- a/core/modules/navigation/config/install/navigation.settings.yml +++ b/core/modules/navigation/config/install/navigation.settings.yml @@ -1,5 +1,7 @@ -logo_provider: default -logo_managed: null -logo_max_filesize: 1048576 -logo_height: 40 -logo_width: 40 +logo: + provider: default + managed: null + max: + filesize: 1048576 + height: 40 + width: 40 diff --git a/core/modules/navigation/config/schema/navigation.schema.yml b/core/modules/navigation/config/schema/navigation.schema.yml index 71fcd374211f33c1a8b28ac82be1cbcb909925cf..0d898740431d2c8c3773b7ecffdc24da068ac391 100644 --- a/core/modules/navigation/config/schema/navigation.schema.yml +++ b/core/modules/navigation/config/schema/navigation.schema.yml @@ -6,42 +6,54 @@ navigation.settings: constraints: FullyValidatable: ~ mapping: - logo_provider: - type: string - label: 'Select Navigation logo handling' + logo: + type: mapping + label: 'Logo settings' + mapping: + provider: + type: string + label: 'Select Navigation logo handling' + constraints: + Choice: + - default + - hide + - custom + managed: + type: integer + label: 'Custom logo' + nullable: true + constraints: + Range: + min: 0 + max: + type: mapping + label: 'Logo maximum settings' + mapping: + filesize: + type: integer + label: 'Maximum file sizes (bytes)' + constraints: + NotNull: [ ] + Range: + min: 0 + height: + type: integer + label: 'Logo expected height' + constraints: + NotNull: [ ] + Range: + min: 0 + width: + type: integer + label: 'Logo expected width' + constraints: + NotNull: [ ] + Range: + min: 0 + constraints: + ValidKeys: '<infer>' constraints: - Choice: - - default - - hide - - custom - logo_managed: - type: integer - label: 'Custom logo' - nullable: true - constraints: - Range: - min: 0 - logo_max_filesize: - type: integer - label: 'Maximum file sizes (bytes)' - constraints: - NotNull: [ ] - Range: - min: 0 - logo_height: - type: integer - label: 'Logo expected height' - constraints: - NotNull: [ ] - Range: - min: 0 - logo_width: - type: integer - label: 'Logo expected width' - constraints: - NotNull: [ ] - Range: - min: 0 + ValidKeys: '<infer>' navigation.block_layout: type: config_object diff --git a/core/modules/navigation/navigation.install b/core/modules/navigation/navigation.install index 6730832c429241497db31c73038886480f2261f2..4b39baad172aa5990ad9380aa58e56d27d94065d 100644 --- a/core/modules/navigation/navigation.install +++ b/core/modules/navigation/navigation.install @@ -23,3 +23,22 @@ function navigation_requirements($phase) { return $requirements; } + +/** + * Reorganizes the values for the logo settings. + */ +function navigation_update_11001(array &$sandbox): void { + $settings = \Drupal::configFactory()->getEditable('navigation.settings'); + $settings->setData([ + 'logo' => [ + 'provider' => $settings->get('logo_provider'), + 'managed' => $settings->get('logo_managed'), + 'max' => [ + 'filesize' => $settings->get('logo_max_filesize'), + 'height' => $settings->get('logo_height'), + 'width' => $settings->get('logo_width'), + ], + ], + ]); + $settings->save(TRUE); +} diff --git a/core/modules/navigation/src/Form/SettingsForm.php b/core/modules/navigation/src/Form/SettingsForm.php index 98613c23e2562d58bf3863c5725a65c00ef5d976..4f0cda9273aabd0e3b5675a880a9a75c19fe7bfe 100644 --- a/core/modules/navigation/src/Form/SettingsForm.php +++ b/core/modules/navigation/src/Form/SettingsForm.php @@ -108,7 +108,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array { NavigationRenderer::LOGO_PROVIDER_HIDE => $this->t('Hide logo'), NavigationRenderer::LOGO_PROVIDER_CUSTOM => $this->t('Custom logo'), ], - '#config_target' => 'navigation.settings:logo_provider', + '#config_target' => 'navigation.settings:logo.provider', ]; $form['logo']['image'] = [ '#type' => 'container', @@ -119,8 +119,8 @@ public function buildForm(array $form, FormStateInterface $form_state): array { ], ]; $allowed = 'png jpg jpeg'; - $current_logo_managed_fid = $config->get('logo_managed') ? [$config->get('logo_managed')] : NULL; - $max_navigation_allowed = $config->get('logo_max_filesize'); + $current_logo_managed_fid = $config->get('logo.managed') ? [$config->get('logo.managed')] : NULL; + $max_navigation_allowed = $config->get('logo.max.filesize'); $max_system_allowed = Environment::getUploadMaxSize(); $max_allowed = $max_navigation_allowed < $max_system_allowed ? $max_navigation_allowed : $max_system_allowed; $upload_validators = [ @@ -166,8 +166,8 @@ public function submitForm(array &$form, FormStateInterface $form_state): void { $config = $this->config('navigation.settings'); // Get the previous config settings. - $previous_logo_provider = $config->get('logo_provider'); - $previous_logo_fid = $config->get('logo_managed'); + $previous_logo_provider = $config->get('logo.provider'); + $previous_logo_fid = $config->get('logo.managed'); // Get new values from the form. $new_logo_provider = $form_state->getValue('logo_provider'); @@ -195,7 +195,7 @@ public function submitForm(array &$form, FormStateInterface $form_state): void { } $config - ->set('logo_managed', $new_logo_fid) + ->set('logo.managed', $new_logo_fid) ->save(); parent::submitForm($form, $form_state); } @@ -215,12 +215,12 @@ protected function validateLogoManaged(array $form, FormStateInterface $form_sta return; } - $width = $config->get('logo_width'); - $height = $config->get('logo_height'); + $width = $config->get('logo.max.width'); + $height = $config->get('logo.max.height'); // Skip if the fid has not been modified. $fid = reset($logo_managed); - if ($fid == $config->get('logo_managed')) { + if ($fid == $config->get('logo.managed')) { return; } @@ -251,8 +251,8 @@ protected function adjustLogoDimensions(File $file): bool { return FALSE; } - $width = $config->get('logo_width'); - $height = $config->get('logo_height'); + $width = $config->get('logo.max.width'); + $height = $config->get('logo.max.height'); if ($image->getWidth() <= $width && $image->getHeight() <= $height) { return TRUE; diff --git a/core/modules/navigation/src/NavigationRenderer.php b/core/modules/navigation/src/NavigationRenderer.php index 58c5b86dbdcf49b6866b3265f65d9c437b82e275..8613174787b52bb2a558ee8f812d848031632c33 100644 --- a/core/modules/navigation/src/NavigationRenderer.php +++ b/core/modules/navigation/src/NavigationRenderer.php @@ -101,7 +101,7 @@ public function removeToolbar(array &$page_top): void { */ public function buildNavigation(array &$page_top): void { $logo_settings = $this->configFactory->get('navigation.settings'); - $logo_provider = $logo_settings->get('logo_provider'); + $logo_provider = $logo_settings->get('logo.provider'); $cacheability = new CacheableMetadata(); $contexts = [ @@ -144,7 +144,7 @@ public function buildNavigation(array &$page_top): void { $page_top['navigation'] = $build; if ($logo_provider === self::LOGO_PROVIDER_CUSTOM) { - $logo_managed = File::load($logo_settings->get('logo_managed')); + $logo_managed = File::load($logo_settings->get('logo.managed')); if ($logo_managed instanceof FileInterface) { $logo_managed_uri = $logo_managed->getFileUri(); $logo_managed_url = $this->fileUrlGenerator->generateAbsoluteString($logo_managed_uri); diff --git a/core/modules/navigation/tests/src/Functional/NavigationLogoTest.php b/core/modules/navigation/tests/src/Functional/NavigationLogoTest.php index 52d6cb22582950c0d3d6fd63595368aa4c77a417..f0f65cf471d1bfead241e5c58fb5008ce338b5f2 100644 --- a/core/modules/navigation/tests/src/Functional/NavigationLogoTest.php +++ b/core/modules/navigation/tests/src/Functional/NavigationLogoTest.php @@ -92,8 +92,8 @@ public function testSettingsLogoOptionsForm(): void { // Preset the configuration to verify a custom image is being seen. $config = $this->configFactory->getEditable('navigation.settings'); - $config->set('logo_provider', 'custom'); - $config->set('logo_managed', $logo_file->id()); + $config->set('logo.provider', 'custom'); + $config->set('logo.managed', $logo_file->id()); $config->save(); // Refresh the page to verify custom logo is placed. $this->drupalGet('/admin/config/user-interface/navigation/settings'); diff --git a/core/modules/navigation/tests/src/FunctionalJavascript/NavigationSettingsFormTest.php b/core/modules/navigation/tests/src/FunctionalJavascript/NavigationSettingsFormTest.php index 707c2977054facf649aae3e5f4a32244d9b955be..746ec4a4be7d4919b695d7a519c11eac28b60741 100644 --- a/core/modules/navigation/tests/src/FunctionalJavascript/NavigationSettingsFormTest.php +++ b/core/modules/navigation/tests/src/FunctionalJavascript/NavigationSettingsFormTest.php @@ -38,8 +38,8 @@ protected function setUp(): void { // Set expected logo dimensions smaller than core provided test images. \Drupal::configFactory()->getEditable('navigation.settings') - ->set('logo_height', 10) - ->set('logo_width', 10) + ->set('logo.max.height', 10) + ->set('logo.max.width', 10) ->save(); }