diff --git a/CHANGELOG.md b/CHANGELOG.md index f12c719..596e277 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ This file covers the 4.x line (Silverstripe 4 and 5). Later releases are documented on `main`. +## 4.0.19 (2026-11-03) + +### Fixed + +- **The placeholder of a shortcode whose record was deleted no longer ends in a 500** (#6). The + placeholder endpoint looked the `ObjectID` up with `byID()` and called a method on the result, which + is `null` once the record is gone. The class singleton now answers instead, as it already did for a + shortcode without an ID, so the editor shows a placeholder. + +### Changed + +- **A shortcodable class without its parser method throws a `LogicException`** (#5), with the same + message, instead of `user_error(..., E_USER_ERROR)`, which PHP 8.4 deprecates. + **Behaviour change:** on a misconfigured site this is now an uncaught (but catchable) exception + instead of a fatal error; every request still fails until the class is fixed. + ## 4.0.18 (2026-11-02) ### Security diff --git a/src/Controllers/ShortcodableAdminController.php b/src/Controllers/ShortcodableAdminController.php index bff4088..ab2000a 100644 --- a/src/Controllers/ShortcodableAdminController.php +++ b/src/Controllers/ShortcodableAdminController.php @@ -153,9 +153,13 @@ public function shortcodePlaceHolder($request) return; } + $object = null; if ($object_id && is_subclass_of($sc_class, DataObject::class)) { $object = $sc_class::get()->byID($object_id); - } else { + } + # No ObjectID, not a DataObject, or a record that no longer exists (deleted after the shortcode was + # inserted): the class singleton answers, so the editor gets a placeholder instead of a 500 (#6) + if (!$object) { $object = singleton($sc_class); } diff --git a/src/Shortcodable.php b/src/Shortcodable.php index b3e1369..2e32a32 100644 --- a/src/Shortcodable.php +++ b/src/Shortcodable.php @@ -2,6 +2,7 @@ namespace Shortcodable; +use LogicException; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Configurable; @@ -39,7 +40,10 @@ public static function register_class($class) $parseMethodName = Config::inst()->get($class, 'shortcode_callback') ?: 'parse_shortcode'; if (!singleton($class)->hasMethod($parseMethodName)) { - user_error("Failed to register \"$class\" with Shortcodable: missing/unconfigured shortcode parser method (looked for: $parseMethodName)", E_USER_ERROR); + # An exception rather than user_error(..., E_USER_ERROR): PHP 8.4 deprecates passing E_USER_ERROR to + # trigger_error() (#5). Same message; it still stops the request, on every request, until fixed. +// user_error("Failed to register \"$class\" with Shortcodable: missing/unconfigured shortcode parser method (looked for: $parseMethodName)", E_USER_ERROR); + throw new LogicException("Failed to register \"$class\" with Shortcodable: missing/unconfigured shortcode parser method (looked for: $parseMethodName)"); } // if (!$shortcode = Config::inst()->get($class, 'shortcode')) { // user_error("Registering \"$class\" with short classname as shortcode: missing \$shortcode config value", E_USER_NOTICE);