Undefined index: changefreq Notice message

Created on 24 July 2019, over 5 years ago
Updated 19 July 2024, 5 months ago

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.

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024