Skip to content
Snippets Groups Projects
Unverified Commit d23a9f37 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3474123 by plopesc, smustgrave, alexpott: Reorganize navigation...

Issue #3474123 by plopesc, smustgrave, alexpott: Reorganize navigation settings to be more consistent
parent 06796271
Branches
Tags
17 merge requests!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!8736Update the Documention As per the Function uses.,!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #302650 canceled
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
......@@ -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
......
......@@ -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);
}
......@@ -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;
......
......@@ -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);
......
......@@ -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');
......
......@@ -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();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment