Problem
When editing the Basic Page content type (/admin/structure/types/manage/page), we are getting the following error message.
Error message:
Notice: Undefined index: changefreq in Drupal\simple_sitemap\Form\FormHelper->displayEntitySettings() (line 337 of modules\contrib\simple_sitemap\src\Form\FormHelper.php).
Drupal\simple_sitemap\Form\FormHelper->displayEntitySettings(Array) (Line: 56)
simple_sitemap_form_alter(Array, Object, 'node_type_edit_form') (Line: 539)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'node_type_edit_form') (Line: 835)
Drupal\Core\Form\FormBuilder->prepareForm('node_type_edit_form', Array, Object) (Line: 277)
Drupal\Core\Form\FormBuilder->buildForm('node_type_edit_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to Reproduce
- Install Simple Sitemap and create a default sitemap
- Navigate to Basic Page edit screen (
/admin/structure/types/manage/page)
- At the bottom, click the
Simple Sitemaptab
- Set
Index entities of type Basic page in variant Default to true, Priority = 0.5, Changefreq = - not specified -
- Leave all else as is and save settings
- Refresh the edit screen and see error message.
Line of Code
// Changefreq
$form_fragment['settings'][$variant]['changefreq_' . $variant . '_' . $this->getEntityTypeId() . '_settings'] = [
'#type' => 'select',
'#title' => $this->t('Change frequency'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The frequency with which this <em>@bundle</em> entity changes. Search engine bots may take this as an indication of how often to index it.', ['@bundle' => $bundle_name])
: $this->t('The frequency with which entities of this type change. Search engine bots may take this as an indication of how often to index them.'),
'#default_value' => $this->settings[$variant]['changefreq'],
'#options' => $this->getChangefreqSelectValues(),
'#states' => [
'visible' => [':input[name="index_' . $variant . '_' . $this->getEntityTypeId() . '_settings"]' => ['value' => 1]],
],
];
Use cases
- Not all Basic pages will have the same change freq so we don't set the default value as content editors want to control that.
- In one month, as many 10 pages may be added to the system of which only 3-4 get modified.
- In another month, as many 2 pages may be added to the system of which none get modified
Proposed Solution
Add validation so that if the changefreq is set to - Not specified -, there is a value available for that.
Comments
Comment #2
drup16 commentedComment #3
drup16 commentedComment #4
drup16 commentedComment #5
drup16 commentedAn additional note is that
changefreqhasn't been important for some time now. See Google: Priority & Change Frequency In Sitemap Doesn't Play Much Of A RoleComment #6
ValeriyTolmachov commentedI couldn't reproduce the issue on a clean site.
Comment #7
lupusgr3y commentedUpdated from version 3.2 and got the same issue when editing nodes.
Comment #8
robin.ingelbrecht commentedI can confirm this issue in version 3.3
Comment #9
farnoosh commentedSame issue on version 3.3
Comment #10
robin.ingelbrecht commentedIf found that if you re-save the entity types, the error is gone. This is probably only an issue if you run the update hooks. So not on a fresh installation.
Comment #11
gbyteI tested both the use cases (new installation and upgrade from 2.x) and found no problems.
Fresh install on Drupal 8.7:
Result: no erros
Upgrade from simple_sitemap 2.1 on Drupal 8.7:
drush updb, be surprised by dozens of update hooks runningResult: no erros
So unless someone can provide a reproducible way of getting this error, I will have to close this issue.
Comment #12
gbyteClosing due to lack of activity.
Comment #13
pio.fernandes commentedI have this also, after upgrading 2.12.0 to 3.4.0, when creating new (e.g. page) content. It goes away if I set a default value on content type level, in the settings form for the content type.
Notice: Undefined index: changefreq in Drupal\simple_sitemap\Form\FormHelper->displayEntitySettings() (line 344 of modules/contrib/simple_sitemap/src/Form/FormHelper.php).
Comment #14
gbyte@pio.fernandes
As you see in comment #11 I could not reproduce the issue. Feel free to write up a reproducible way of getting it, then I'll be happy to look for a code solution.
Comment #15
bryanmws commentedStill having this issue.
Drupal: 8.7.10
Simple Sitemap: 3.5
Comment #16
drup16 commentedIt seems to be related to existing installs where new content types are added or when existing content types are modified.
Comment #17
gbyteSee #14.
Comment #18
jepster_Added check for not existing variable.
Comment #19
gbyte@Peter Majmesku Thanks, but that's not helping. Please refer to #14.
Comment #20
gbyteClosing as per lack of activity.
Comment #21
boby_ui commentedI confirm that it working with 8.x-3.4 had this issue but #18 patch fixed the issue
Comment #22
gbyteThe issue's not fixed if you need a patch to make it work.
If anyone can reproduce on a clean 3.x-dev install, feel free to reopen this.
Comment #23
mstrelan commentedI believe the issue occurs when you install the site from an install profile that is missing the changefreq setting. For example, in GovCMS.
Comment #24
gemalmI get this error for the version 3.7.0
The patch #18 fixed the issue.
Comment #25
gemalmComment #26
gbyte@germalm This is not helpful, as mentioned multiple times, I would like to know the reason why this is happening and have it happen on a clean install before I commit changes that somehow fix an issue that should not be happening in the first place.
Comment #27
froboyI can +1 this issue and the patch in #18. I'm also on a distro (Open Y). I believe #23 is onto something, but recreating the issue is going to be challenging. Most likely it will involve something like:
- install an older version of a distro
- create some content
- run some updates
- update the version of simple_sitemap
- observe the error
I've also seen a similar error:
Notice: Undefined index: include_images in Drupal\simple_sitemap\Form\FormHelper->displayEntitySettings() (line 363 of modules/contrib/simple_sitemap/src/Form/FormHelper.php).with a similar fix:
'#default_value' => !empty($this->settings[$variant]['include_images']) ? (int) $this->settings[$variant]['include_images'] : 0,Comment #29
froboyI've opened a MR with the patch and a fix for my issue. I understand the hesitation for committing this fix, but hopefully this patch can help folks who are running into issues in the mean time.
Comment #30
podarok#28 looks good
We added it to Open Y today's release
https://github.com/ymcatwincities/openy/pull/2399
Comment #32
gbyteApparently no one can reproduce this but as it seems to randomly happen to people, I am caving in and adding that check. Thanks for everyone who tried to reproduce.
@podarok No good using an empty() check if 0 is a valid priority. Please be mindful when marking stuff RTBC.
Comment #33
podarokThank you @gbyte