Missing route causes ajax error when editing recurring event instances

Created on 27 February 2023, almost 2 years ago
Updated 2 March 2023, almost 2 years ago

Problem/Motivation

Under certain circumstances, when using Smart Date Recur, an ajax error is encountered when editing/overriding an event series instance. This was originally reported in issue #3210447 but the reporting user resolved the issue, and the issue was closed (as expected) due to lack of information and subsequent resolution.

The error is as follows:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /admin/content/smart_date_recur/154/instance/reschedule/10/ajax?_wrapper_format=drupal_ajax&ajax_form=1
StatusText: error
ResponseText: The website encountered an unexpected error. Please try again later.Drupal\Core\Entity\EntityStorageException: Route "entity.smart_date_override.canonical" does not exist. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 815 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php)."

This is caused due to a missing `entity.smart_date_override.canonical` route. The 'canonical' link template is definined in the Smart Date Override entity definition, but no corresponding route is provided. The problem is encountered when, for instance, custom/contrib code is creating a url string for the Smart Date Override entity. As it happens, the Next module is doing this for entities in an entity_insert hook.

The Smart Date Override entity defines these link templates:

 *     "canonical" = "/admin/content/smart_date_recur/overrides/{smart_date_override}",
 *     "add-form" = "/admin/content/smart_date_recur/overrides/add",
 *     "edit-form" = "/admin/content/smart_date_recur/overrides/{smart_date_override}/edit",
 *     "delete-form" = "/admin/content/smart_date_recur/overrides/{smart_date_override}/delete",
 *     "collection" = "/admin/content/smart_date_recur/overrides",

The Smart Date Recur module defines this route for the Smart Date Override entities:

entity.smart_date_override.delete_form:
  path: '/admin/content/smart_date_recur/overrides/{smart_date_override}/delete'
  defaults:
    # Calls the form.delete controller, defined in the smart_date_override entity.
    _entity_form: smart_date_override.delete
    _title: 'Revert to Default'
  requirements:
    _permission: 'reschedule smart date recur instances'

Steps to reproduce

  1. In a fresh Drupal install, enable smart_date, smart_date_recur, and next modules
  2. Create a new content type: Event
  3. Add a Smart date range field to the Event content type
  4. Configure the smart date range field to allow for recurring events
  5. Create a new Event node which repeats weekly for a few weeks (the number of weeks is not important)
  6. Save the Event node
  7. Edit the Event node, and click the 'manage instances' button to reveal the instance override modal.
  8. Click the 'Override' link for one of the instances.
  9. Change the start or end time for the instance and click the Save button.
  10. Notice the modal doesn't respond to the save attempt.
  11. Open Devtools and see that there is an Drupal.AjaxError error thrown in the console.

Proposed resolution

Remove all but the delete-form link template from the Smart Date Override entity definition.

Remaining tasks

Write a unit test.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

3.7

Component

Smart Date Recur

Created by

πŸ‡ΊπŸ‡ΈUnited States coderdan

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

Comments & Activities

Production build 0.71.5 2024