From a2ccc12c0b2e5e15afe3fd46649ef194d35ba43e Mon Sep 17 00:00:00 2001 From: micschk Date: Tue, 3 Nov 2026 16:56:02 +0100 Subject: [PATCH 1/6] TEST placeholder for a deleted record falls back to the class singleton (#6) Fails on the current code: byID() returns null for an ObjectID that no longer exists and shortcodePlaceHolder() calls hasMethod() on it ("Call to a member function hasMethod() on null"). Pair-programmed with my buddy Claude --- tests/ShortcodableAdminControllerTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/ShortcodableAdminControllerTest.php b/tests/ShortcodableAdminControllerTest.php index f939676..539f3de 100644 --- a/tests/ShortcodableAdminControllerTest.php +++ b/tests/ShortcodableAdminControllerTest.php @@ -185,6 +185,23 @@ public function testDefaultPlaceholderConfigChangesTheSize() $this->assertEquals(77, $query['h']); } + public function testPlaceholderForADeletedRecordFallsBackToTheClassSingleton() + { + // An ObjectID whose record no longer exists (deleted after the shortcode was inserted) must not + // end in a 500 from calling a method on null (#6): the class singleton answers instead, here + // with the default SVG placeholder, as for a request without an ObjectID. + $missingId = 999999; + $this->assertNull(ShortcodableRecord::get()->byID($missingId)); + + $this->logInAsCmsUser(); + $this->autoFollowRedirection = false; + $response = $this->get('admin/shortcodable/placeholder/sc_record/' . $missingId . '?sc=' + . urlencode('[sc_record id="' . $missingId . '"]')); + + $this->assertSame(302, $response->getStatusCode()); + $this->assertSame('[sc_record id="' . $missingId . '"]', $this->redirectQuery($response)['txt']); + } + public function testPlaceholderForAnUnknownShortcodeIsEmpty() { $this->logInAsCmsUser(); From d4b235cb1cf2ff79cd26339fa4791e0814ffd229 Mon Sep 17 00:00:00 2001 From: micschk Date: Tue, 3 Nov 2026 16:56:03 +0100 Subject: [PATCH 2/6] TEST register_class() without a parser method throws a LogicException (#5) Fails on the current code, which raises user_error(..., E_USER_ERROR); PHP 8.4 deprecates passing E_USER_ERROR to trigger_error(). Pair-programmed with my buddy Claude --- tests/ShortcodableTest.php | 14 ++++++++++++++ tests/Stub/MissingParserShortcode.php | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/Stub/MissingParserShortcode.php diff --git a/tests/ShortcodableTest.php b/tests/ShortcodableTest.php index 6d92dff..9ca2f3e 100644 --- a/tests/ShortcodableTest.php +++ b/tests/ShortcodableTest.php @@ -5,6 +5,7 @@ use Shortcodable\Shortcodable; use Shortcodable\Tests\Stub\BlockShortcode; use Shortcodable\Tests\Stub\CustomCallbackShortcode; +use Shortcodable\Tests\Stub\MissingParserShortcode; use Shortcodable\Tests\Stub\ShortcodableRecord; use Shortcodable\Tests\Stub\SimpleShortcode; use SilverStripe\Admin\LeftAndMain; @@ -75,6 +76,19 @@ public function testRegisterClassIgnoresClassesThatDoNotExist() $this->assertSame($before, ShortcodeParser::get()->getRegisteredShortcodes()); } + public function testRegisterClassWithoutItsParserMethodThrows() + { + // A LogicException, not user_error(..., E_USER_ERROR): PHP 8.4 deprecates passing E_USER_ERROR + // to trigger_error() (#5). The message stays the same, so it still names the class and method. + $this->expectException(\LogicException::class); + $this->expectExceptionMessage( + 'Failed to register "' . MissingParserShortcode::class . '" with Shortcodable: ' + . 'missing/unconfigured shortcode parser method (looked for: parse_shortcode)' + ); + + Shortcodable::register_class(MissingParserShortcode::class); + } + public function testRegisterClassesRegistersEachClass() { $this->registeredTags = ['sc_simple', 'sc_block']; diff --git a/tests/Stub/MissingParserShortcode.php b/tests/Stub/MissingParserShortcode.php new file mode 100644 index 0000000..eb06950 --- /dev/null +++ b/tests/Stub/MissingParserShortcode.php @@ -0,0 +1,22 @@ + Date: Tue, 3 Nov 2026 16:56:57 +0100 Subject: [PATCH 3/6] FIX placeholder for a deleted record falls back to the class singleton (#6) shortcodePlaceHolder() took the byID() result as is, so an ObjectID whose record no longer exists ended in a 500 (hasMethod() on null). The class singleton now answers, as it already did for a request without an ObjectID. Pair-programmed with my buddy Claude --- src/Controllers/ShortcodableAdminController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Controllers/ShortcodableAdminController.php b/src/Controllers/ShortcodableAdminController.php index 162d61e..028d697 100644 --- a/src/Controllers/ShortcodableAdminController.php +++ b/src/Controllers/ShortcodableAdminController.php @@ -154,9 +154,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); } From add4a56cd0444723509aa67dfc822061aff7a97d Mon Sep 17 00:00:00 2001 From: micschk Date: Tue, 3 Nov 2026 16:57:18 +0100 Subject: [PATCH 4/6] FIX register_class() throws a LogicException instead of E_USER_ERROR (#5) PHP 8.4 deprecates passing E_USER_ERROR to trigger_error(). The message is unchanged. Behaviour change for a misconfigured site: a catchable LogicException instead of a fatal error. Pair-programmed with my buddy Claude --- src/Shortcodable.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Shortcodable.php b/src/Shortcodable.php index 5db9502..bbfa6ce 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); From 7844e4961d0966069d59d5ac54e6bbc34c5a13b6 Mon Sep 17 00:00:00 2001 From: micschk Date: Tue, 3 Nov 2026 16:57:53 +0100 Subject: [PATCH 5/6] DOCS README: a class without its parser method throws a LogicException (#5) Pair-programmed with my buddy Claude --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d6b1d33..e619690 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,8 @@ Implement these methods on your shortcodable classes (they may also be added via **NOTE: the parser method gets called on a singleton object instance.**
(So there's no `$this->ID` or `$this->owner->ID` etc.) -A registered class without its parser method is a fatal error (`E_USER_ERROR`) when the -shortcodes are registered, on every request. +A registered class without its parser method throws a `LogicException` when the shortcodes are +registered, so every request fails until it is fixed (up to 5.2.1 this was a fatal `E_USER_ERROR`). A plain class (not a DataObject) needs the `Extensible` trait: the module checks methods with `hasMethod()`, which comes from that trait (`DataObject` and `ViewableData`/`ModelData` subclasses From 42a2112b9656f90c879efce6429bb752025ad438 Mon Sep 17 00:00:00 2001 From: micschk Date: Tue, 3 Nov 2026 16:58:02 +0100 Subject: [PATCH 6/6] CHANGELOG 5.2.2 Pair-programmed with my buddy Claude --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11a1335..594c3e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## 5.2.2 (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. + ## 5.2.1 (2026-11-02) ### Security