Badgelayouts cannot be edited with PHP warning
Reproduced on dmaster and locally on WordPress
Steps to reproduce
- Navigate to "Administer CiviCRM", "Event Name Badge Layouts".
- Create a new name badge
- Edit the newly created name badge.
Expected outcode The edit screen should be pre-filled with the values entered initially.
Actual outcome
Each field is blank, a PHP warning is shown:
Technical explanation The bug was introduced in https://github.com/civicrm/civicrm-core/commit/873bfeb503caa413f17460dbe450b74fac3d6dbf.
The commit above added a new tokens:
'{event.start_date|crmDate:"%B %E%f"}' => ts('Event Start Date'),
'{event.end_date|crmDate:"%B %E%f"}' => ts('Event End Date'),`
The data for badge layouts is stored as encoded JSON. This means that the quote marks in these two tokens are being wrapped in double-quotes for the string, causing something like "{event.start_date|crmDate:"%B %E%f"}"
. As such the JSON is not valid and cannot be json_decode
ed.
The actual fix could be straightforward enough: Switch the tokens to use single instead of double quotes. However, I'm not sure what the correct solution is for any broken JSON which is now stored in CiviCRM databases. Some sort of upgrade script might be required to find/replace the known broken JSON.
Pinging @eileen who did a lot of work on tokens last year.