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
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | After Patch 2.png | 39.51 KB | sandeep_k |
| #7 | After Patch 1.png | 120.67 KB | sandeep_k |
| #7 | Before Patch.png | 190.81 KB | sandeep_k |
| #6 | Issues-3407927-favicon-disappears-in-theme-fixes.patch | 995 bytes | viren18febs |
| #5 | 3407927-Error-screen-#3.png | 148.18 KB | abhaypai |
Issue fork drupal-3407927
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
Comment #3
viren18febs commentedHi @NicklasMF
I have added a changes ,please review this patch.
Thanks
Comment #4
sandeep_k commentedVerified 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.
Comment #5
abhaypai commentedThanks @viren18febs for sharing the fix as proposal.
Few inputs i wanna share here are :
{TheRightElement}is just a placeholder which @NicklasMF has shared.{TheRightElement}in the codeSharing 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.
Comment #6
viren18febs commentedI have update the patch file with element value, please review.
Comment #7
sandeep_k commentedThanks, @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:
Testing Results:
The user is unable to save while the favicon checkbox is unchecked.
Moving this ticket to RTBC.
Comment #8
sandeep_k commentedComment #9
cilefen commentedWhere are the tests that someone asked for? Also, what is the meaning of all these screenshots of code?