Problem/Motivation

When attempting to set a favicon for a theme in the theme settings, an issue arises if neither default_favicon, favicon_upload, nor favicon_path is explicitly set. This results in the favicon being incorrectly set to FALSE, preventing it from being displayed in the settings form.

The problem originates in the theme.inc file, specifically in line 317, where features.favicon is set to FALSE and cannot be reset to TRUE.

// Generate the path to the favicon.
if ($cache[$theme]->get('features.favicon')) {
  // ... (code snippet)
  $cache[$theme]->set('features.favicon', FALSE);
}

Additionally, in ThemeSettingsForm.php, line 258 ensures that the Favicon details are hidden and cannot be restored:

'input[name="toggle_favicon"]' => ['checked' => FALSE],

Steps to reproduce

  • Navigate to the settings page for your theme, e.g., the backend theme Claro.
  • Uncheck the checkbox "Use the favicon supplied by the theme" and leave the two fields that appear empty.
  • Save the form.
  • The form elements for Favicon no longer appear.

Proposed resolution

Add validation to the form fields to ensure that at least one of the settings (default_favicon, favicon_upload, or favicon_path) is provided. This prevents the issue of the favicon being incorrectly set to FALSE and ensures proper functionality.

ThemeSettingsForm.php, l. 453 in validateForm():

// Check that at least one setting for the favicon is provided.
if (empty($form_state->getValue('default_favicon')) && empty($form_state->getValue('favicon_upload')) && empty($form_state->getValue('favicon_path'))) {
  $form_state->setErrorByName({TheRightElement}, $this->t('Please provide at least one of the following: Default Favicon, Favicon Upload, or Favicon Path.'));
}

Remaining tasks

Release notes snippet

Issue fork drupal-3407927

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

NicklasMF created an issue. See original summary.

viren18febS made their first commit to this issue’s fork.

viren18febs’s picture

Status: Active » Needs review
StatusFileSize
new1003 bytes

Hi @NicklasMF
I have added a changes ,please review this patch.
Thanks

sandeep_k’s picture

Verified this on Drupal version- 10.1.7-dev and was able to apply the patch Issues-3407927-favicon-disappears-in-theme-fixes.patch successfully with a warning, see attached screenshot.
After applying the patch, while trying to reverify the issue site broke when we clicked on the theme setting-

Steps to Reproduce-
Go to Appearance, and Click on Setting.

abhaypai’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
StatusFileSize
new813.79 KB
new46.29 KB
new148.18 KB

Thanks @viren18febs for sharing the fix as proposal.

Few inputs i wanna share here are :

  1. #3 patch applied successfully via composer
  2. Error is appearing in the settings because you haven't defined correct element for form element name
  3. {TheRightElement} is just a placeholder which @NicklasMF has shared.
  4. Please understand the logic of Default Favicon, Favicon Upload, or Favicon Path and then appropriately replace form element with {TheRightElement} in the code

Sharing screenshot for reference and code reference explicitly attached to understand which point i am talking about.
Also changing the status to Needs work and as a bug will need a test case to move the issue forward.

viren18febs’s picture

Status: Needs work » Needs review
StatusFileSize
new995 bytes

I have update the patch file with element value, please review.

sandeep_k’s picture

StatusFileSize
new190.81 KB
new120.67 KB
new39.51 KB

Thanks, @viren18febs for sharing the fix.

Verified and tested patch Issues-3407927-favicon-disappears-in-theme-fixes.patch on the Drupal version- 10.1.8-dev. The patch was applied successfully and looks good to me.

Testing Steps:

  1. Apply patch Issues-3407927-favicon-disappears-in-theme-fixes.patch
  2. Go to Appearance> Open Setting.
  3. Uncheck the favicon checkbox & click save.

Testing Results:
The user is unable to save while the favicon checkbox is unchecked.

Moving this ticket to RTBC.

sandeep_k’s picture

Status: Needs review » Reviewed & tested by the community
cilefen’s picture

Status: Reviewed & tested by the community » Needs work

Where are the tests that someone asked for? Also, what is the meaning of all these screenshots of code?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.