Ajax error when inserting an empty me_template into a page

Created on 7 May 2025, 8 days ago

Problem/Motivation

Attempting to add an empty mercury editor template to a page results in an ajax error thrown with the following error:

Error: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 77 of modules/contrib/mercury_editor/modules/mercury_editor_templates/src/Controller/InsertTemplateController.php)

Lines 76-77 of the above file are:

    // Append to the end of the list if no sibling uuid is provided.
    $delta = count($source_components);

Steps to reproduce

- Create an mercury editor template. Assign it a label but no content. Save.
- Create a new page and add the mercury editor template into the page.
- Observe browser console messages.

Proposed resolution

Either or both of the following:
- Update the line that runs `count($source_components);` to be more robust - test that $source_components is not empty and assign an appropriate value to $delta if it is empty.
- Add validation to the me_template entity create/edit forms to prevent me_template with empty content from being saved.

🐛 Bug report
Status

Active

Version

2.2

Component

Code

Created by

🇬🇧United Kingdom andrew robinson

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

Comments & Activities

Production build 0.71.5 2024