Skip to content
Snippets Groups Projects
Verified Commit 85a4d771 authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3443810 by SKAUGHT, plopesc, DishaKatariya, finnsky, smustgrave,...

Issue #3443810 by SKAUGHT, plopesc, DishaKatariya, finnsky, smustgrave, ckrina, Prashant.c, larowlan: Custom Navigation logo is disconnected from new Layout template

(cherry picked from commit f479374e)
parent a051706f
Branches
Tags
32 merge requests!10663Issue #3495778: Update phpdoc in FileSaveHtaccessLoggingTest,!10451Issue #3472458 by watergate, smustgrave: CKEditor 5 show blocks label is not translated,!103032838547 Fix punctuation rules for inline label suffix colon with CSS only,!10150Issue #3467294 by quietone, nod_, smustgrave, catch, longwave: Change string...,!10130Resolve #3480321 "Second level menu",!9936Issue #3483087: Check the module:// prefix in the translation server path and replace it with the actual module path,!9933Issue #3394728 by ankondrat4: Undefined array key "#prefix" and deprecated function: explode() in Drupal\file\Element\ManagedFile::uploadAjaxCallback(),!9914Issue #3451136 by quietone, gapple, ghost of drupal past: Improve...,!9882Draft: Issue #3481777 In bulk_form ensure the triggering element is the bulk_form button,!9839Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9815Issue #3480025: There is no way to remove entity cache items,!9757Issue #3478869 Add "All" or overview links to parent links,!9752Issue #3439910 by pooja_sharma, vensires: Fix Toolbar tests that rely on UID1's super user behavior,!9749Issue #3439910 by pooja_sharma, vensires: Fix Toolbar tests that rely on UID1's super user behavior,!9678Issue #3465132 by catch, Spokje, nod_: Show test run time by class in run-tests.sh output,!9578Issue #3304746 by scott_euser, casey, smustgrave: BigPipe cannot handle (GET)...,!9449Issue #3344041: Allow textarea widgets to be used for text (formatted) fields,!8945🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥...,!8893Resolve #3444391 "Navigation center sm logo",!8772Issue #3445909 by seanB, smustgrave, alexpott, catch: Add static caching to...,!8723Make dblog entities,!8708Filter out disabled display extenders on save,!8691#3459116 - Update Manager Settings: Validate same email address added multiple times,!8665Issue #3449743 by catch: Try to optimize test ordering when run-tests.sh is...,!8598Draft: Issue #3458215: Migrate Toolbar button to SDC,!8572Reorder checkboxes on "Development settings" page,!8538Issue #3457009: Fixing xxception message thrown.,!8516Update file EntityReferenceItem.php,!8505Issue #3456528: _node_mass_update_batch_process fails during user cancel when revision is deleted,!8494Issue #3452511: Convert ProviderRepositoryTest to a kernel test,!8482Resolve #3456202 "Phpunit tests support",!8463Prevent re-install if site already exists
Pipeline #198530 passed
......@@ -234,6 +234,7 @@ body {
}
.admin-toolbar__logo img {
display: block;
max-width: var(--admin-toolbar-space-40);
}
/**
* Scroll wrapper for Mobile.
......
......@@ -244,6 +244,7 @@ body {
& img {
display: block;
max-width: var(--admin-toolbar-space-40);
}
}
......
......@@ -6,14 +6,13 @@
* Available variables:
* - content: The content for this layout.
* - attributes: HTML attributes for the layout <div>.
* - hide_logo: Whether to hide the logo.
* - logo_path: The path to the logo image if logo_managed in
* navigation.settings configuration has been set.
* - logo_width: The width of the logo image. Available if
* - content.settings.hide_logo: Whether to hide the logo.
* - content.settings.logo_path: The path to the logo image if logo_managed
* in navigation.settings configuration has been set.
* - content.settings.logo_width: The width of the logo image. Available if
* logo_path points to a valid image file.
* - logo_height: The height of the logo image. Available if
* - content.settings.logo_height: The height of the logo image. Available if
* logo_path points to a valid image file.
*
* @ingroup themeable
*/
#}
......@@ -38,16 +37,15 @@
<div class="admin-toolbar__scroll-wrapper">
{% set title_menu = 'admin-toolbar-title'|clean_unique_id %}
{# @todo - We should get rid of this ID below. #}
<nav {{ region_attributes.content.setAttribute('id', 'menu-builder').addClass('admin-toolbar__content').setAttribute('aria-labelledby', title_menu) }}>
<h3 id="{{ title_menu }}" class="visually-hidden">{{ 'Administrative toolbar content'|t }}</h3>
{# @todo - Needs to be placed here so we can have the header footer on mobile. #}
<div class="admin-toolbar__header">
{% if not hide_logo %}
{% if not content.settings.hide_logo %}
<a class="admin-toolbar__logo" href="{{ path('<front>') }}">
{% if logo_path %}
<img alt="{{ 'Navigation logo'|t }}" src="{{ file_url(logo_path) }}" loading="eager" width="{{ logo_width|default(40) }}" height="{{ logo_height|default(40) }}">
{% if content.settings.logo_path is not null %}
<img alt="{{ 'Navigation logo'|t }}" src="{{ content.settings.logo_path }}" loading="eager" width="{{ content.settings.logo_width|default(40) }}" height="{{ content.settings.logo_height|default(40) }}">
{% else %}
{% include '@navigation/logo.svg.twig' with {
label: 'Navigation logo'|t
......
......@@ -207,13 +207,6 @@ function navigation_block_alter(&$definitions): void {
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function template_preprocess_navigation(array &$variables): void {
$variables['hide_logo'] = $variables['content']['#hide_logo'] ?? TRUE;
}
/**
* Implements hook_element_info_alter().
*/
......
......@@ -125,7 +125,7 @@ public function buildNavigation(array &$page_top): void {
$asset_url = $module_path . '/assets/fonts/inter-var.woff2';
$defaults = [
'#hide_logo' => $logo_provider === self::LOGO_PROVIDER_HIDE,
'settings' => ['hide_logo' => $logo_provider === self::LOGO_PROVIDER_HIDE],
'#attached' => [
'html_head_link' => [
[
......@@ -149,11 +149,11 @@ public function buildNavigation(array &$page_top): void {
if ($logo_managed instanceof File) {
$logo_managed_uri = $logo_managed->getFileUri();
$logo_managed_url = $this->fileUrlGenerator->generateAbsoluteString($logo_managed_uri);
$page_top['navigation']['#logo_path'] = $logo_managed_url;
$page_top['navigation'][0]['settings']['logo_path'] = $logo_managed_url;
$image = $this->imageFactory->get($logo_managed_uri);
if ($image->isValid()) {
$page_top['navigation']['#logo_width'] = $image->getWidth();
$page_top['navigation']['#logo_height'] = $image->getHeight();
$page_top['navigation'][0]['settings']['logo_width'] = $image->getWidth();
$page_top['navigation'][0]['settings']['logo_height'] = $image->getHeight();
}
}
}
......
core/modules/navigation/tests/assets/image_test_files/test-logo.png

2.74 KiB

<?php
declare(strict_types=1);
namespace Drupal\Tests\navigation\Functional;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\file\Entity\File;
use Drupal\Tests\BrowserTestBase;
/**
* Tests for \Drupal\navigation\Form\SettingsForm.
*
* @group navigation
*/
class NavigationLogoTest extends BrowserTestBase {
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* A user with administrative permissions.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'navigation',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// Inject the file_system and config.factory services.
$this->fileSystem = $this->container->get('file_system');
$this->configFactory = $this->container->get('config.factory');
// Create and log in an administrative user.
$this->adminUser = $this->drupalCreateUser([
'administer site configuration',
'access navigation',
]);
$this->drupalLogin($this->adminUser);
}
/**
* Tests Navigation logo configuration base options.
*/
public function testSettingsLogoOptionsForm() {
// Navigate to the settings form.
$this->drupalGet('/admin/config/user-interface/navigation/settings');
$this->assertSession()->statusCodeEquals(200);
// Option 1. Check the default logo provider.
$this->assertSession()->fieldValueEquals('logo_provider', 'default');
$this->assertSession()->elementExists('css', 'a.admin-toolbar__logo > svg');
// Option 2: Set the logo provider to hide and check.
$edit = [
'logo_provider' => 'hide',
];
$this->submitForm($edit, t('Save configuration'));
$this->assertSession()->pageTextContains('The configuration options have been saved.');
$this->assertSession()->elementNotExists('css', 'a.admin-toolbar__logo');
// Option 3: Set the logo provider to custom and upload a logo.
$logo_file = $this->createFile();
$this->assertNotEmpty($logo_file, 'File entity is not empty.');
// 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->save();
// Refresh the page to verify custom logo is placed.
$this->drupalGet('/admin/config/user-interface/navigation/settings');
$this->assertSession()->elementExists('css', 'a.admin-toolbar__logo > img');
$this->assertSession()->elementAttributeContains('css', 'a.admin-toolbar__logo > img', 'src', $logo_file->getFilename());
}
/**
* Helper function to create a file entity.
*
* @return \Drupal\file\FileInterface
* The file entity.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
protected function createFile() {
// Define the file URI and path.
$file_name = 'test-logo.png';
$temp_dir = $this->fileSystem->getTempDirectory();
$file_uri = 'public://' . $file_name;
$logo_path = __DIR__ . '/../../assets/image_test_files/' . $file_name;
$file_contents = file_get_contents($logo_path);
file_put_contents($temp_dir . '/' . $file_name, $file_contents);
// Create a file entity for testing.
$file = File::create([
'uri' => $file_uri,
]);
try {
$file->setPermanent();
$file->save();
}
catch (EntityStorageException $e) {
$this->fail(sprintf('Failed to create file entity: %s', $e->getMessage()));
}
return $file;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment