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

  1. Install Simple Sitemap and create a default sitemap
  2. Navigate to Basic Page edit screen (/admin/structure/types/manage/page)
  3. At the bottom, click the Simple Sitemaptab
  4. Set Index entities of type Basic page in variant Default to true, Priority = 0.5, Changefreq = - not specified -
  5. Leave all else as is and save settings
  6. 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

  1. 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.
  2. In one month, as many 10 pages may be added to the system of which only 3-4 get modified.
  3. 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.

CommentFileSizeAuthor
#18 3070132-changefreq-notice-message.patch1020 bytesjepster_
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

drup16 created an issue. See original summary.

drup16’s picture

Issue summary: View changes
drup16’s picture

Issue summary: View changes
drup16’s picture

Issue summary: View changes
drup16’s picture

An additional note is that changefreq hasn't been important for some time now. See Google: Priority & Change Frequency In Sitemap Doesn't Play Much Of A Role

ValeriyTolmachov’s picture

I couldn't reproduce the issue on a clean site.

lupusgr3y’s picture

Updated from version 3.2 and got the same issue when editing nodes.

robin.ingelbrecht’s picture

I can confirm this issue in version 3.3

farnoosh’s picture

Same issue on version 3.3

robin.ingelbrecht’s picture

If 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.

gbyte’s picture

I tested both the use cases (new installation and upgrade from 2.x) and found no problems.

Fresh install on Drupal 8.7:

  • Install module
  • Set nodes of type page to be indexed leaving out changefreq setting
  • Save
  • Revisit bundle edit page

Result: no erros

Upgrade from simple_sitemap 2.1 on Drupal 8.7:

  • Install simple_sitemap 2.1
  • Set nodes of type page to be indexed
  • Save
  • Upgrade to simple_sitemap 3.x
  • Run drush updb, be surprised by dozens of update hooks running
  • Run /rebuild.php to clear caches without Drupal bootstraping

Result: no erros

So unless someone can provide a reproducible way of getting this error, I will have to close this issue.

gbyte’s picture

Status: Active » Closed (cannot reproduce)

Closing due to lack of activity.

pio.fernandes’s picture

I 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).

gbyte’s picture

@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.

bryanmws’s picture

Still having this issue.

Drupal: 8.7.10
Simple Sitemap: 3.5

drup16’s picture

Status: Closed (cannot reproduce) » Active

It seems to be related to existing installs where new content types are added or when existing content types are modified.

gbyte’s picture

Version: 8.x-3.3 » 8.x-3.5
Status: Active » Postponed (maintainer needs more info)

See #14.

jepster_’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1020 bytes

Added check for not existing variable.

gbyte’s picture

Status: Needs review » Postponed (maintainer needs more info)

@Peter Majmesku Thanks, but that's not helping. Please refer to #14.

gbyte’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Closing as per lack of activity.

boby_ui’s picture

Version: 8.x-3.5 » 8.x-3.4
Status: Closed (cannot reproduce) » Fixed

I confirm that it working with 8.x-3.4 had this issue but #18 patch fixed the issue

gbyte’s picture

Version: 8.x-3.4 » 8.x-3.x-dev
Status: Fixed » Closed (cannot reproduce)

The 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.

mstrelan’s picture

I believe the issue occurs when you install the site from an install profile that is missing the changefreq setting. For example, in GovCMS.

gemalm’s picture

I get this error for the version 3.7.0
The patch #18 fixed the issue.

gemalm’s picture

Status: Closed (cannot reproduce) » Needs work
gbyte’s picture

Status: Needs work » Postponed (maintainer needs more info)

@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.

froboy’s picture

I 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,

froboy’s picture

I'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.

podarok’s picture

Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

#28 looks good
We added it to Open Y today's release
https://github.com/ymcatwincities/openy/pull/2399

  • gbyte committed 65dc43d on 8.x-3.x
    Issue #3070132 by drup16, Peter Majmesku, froboy, gbyte: Undefined index...
gbyte’s picture

Priority: Major » Normal
Status: Reviewed & tested by the community » Fixed

Apparently 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.

podarok’s picture

Thank you @gbyte

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.