Lock default date formats or provide fallback when hard-coding

Created on 30 August 2023, about 1 year ago

If date formats that smart_date installs are used in module functionality, those formats shouldn't be allowed to be removed.

Here's what happened:

When clicking Manage Instances on a recurring event, nothing was happening in the UI; the modal didn't open.

I was getting an error in the console that looked about like this:

Drupal.AjaxError {message: '
An AJAX HTTP error occurred.
HTTP Result Code: 20…ecur/12/instances/1
StatusText: OK
ResponseText: ', name: 'AjaxError', stack: 'Error
    at https://example.com…RlhqEuoO-4LrF2bFOO3G-CMlnxGefGmKzjd7w1Y.js:4076:3'}message: "
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /admin/content/smart_date_recur/12/instances/1
StatusText: OK

Drupal's log showed this:

Error: Call to a member function getOptions() on null in Drupal\smart_date_recur\Controller\Instances->buildRow() (line 235 of web/modules/contrib/smart_date/modules/smart_date_recur/src/Controller/Instances.php)

As it turned out, smart_date was asking to load the "compact" date format for the Manage Instances listing, but I had deleted that format. I restored the format and it worked fine.

I suspect this may be what happened in #3112684: Recurring Display Formatter throws error , and this is also the same error that @banoodle was getting in #3159720: Default formats are not getting installed when module is installed though for apparently different underlying reasons.

🐛 Bug report
Status

Active

Version

4.0

Component

Smart Date Recur

Created by

🇺🇸United States jeffschuler Boulder, Colorado

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

Comments & Activities

  • Issue created by @jeffschuler
  • 🇺🇸United States jeffschuler Boulder, Colorado

    To be clear, the issue is load('compact') in here:

      public function buildRow(array $instance) {
        // Get format settings.
        // @todo make the choice of format configurable?
        $format = $this->entityTypeManager
          ->getStorage('smart_date_format')
          ->load('compact');
    

    And that @todo is relevant.

Production build 0.71.5 2024