From ee3835bcc1efe325364112527b47db93cf13bcbe Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Sun, 21 Aug 2022 16:16:30 +0900
Subject: [PATCH] Issue #3283776 by Wim Leers, lauriii: Make
 CKEditor5PluginDefinition::getElements() consistent with
 CKEditor5PluginDefinition::get*()

---
 .../src/Plugin/CKEditor5PluginDefinition.php      | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php b/core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php
index 7c84ff59b0bd..1f6e96e64e89 100644
--- a/core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php
+++ b/core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php
@@ -444,13 +444,18 @@ public function hasAdminLibrary(): bool {
   /**
    * Gets the list of elements and attributes this plugin allows to create/edit.
    *
-   * @return string[]|false
-   *   FALSE if this plugin does not create/edit any elements or attributes.
-   *   Otherwise a list.
+   * @return string[]
+   *   A list of elements and attributes.
    *
    * @see \Drupal\ckeditor5\Annotation\DrupalAspectsOfCKEditor5Plugin::$elements
+   *
+   * @throws \LogicException
+   *   When called on a plugin definition that has no elements.
    */
-  public function getElements() {
+  public function getElements(): array {
+    if (!$this->hasElements()) {
+      throw new \LogicException('::getElements() should only be called if ::hasElements() returns TRUE.');
+    }
     return $this->drupal['elements'];
   }
 
@@ -498,7 +503,7 @@ public static function isCreatableElement(string $element): bool {
    * @see \Drupal\ckeditor5\Annotation\DrupalAspectsOfCKEditor5Plugin::$elements
    */
   public function hasElements(): bool {
-    return $this->getElements() !== FALSE;
+    return $this->drupal['elements'] !== FALSE;
   }
 
   /**
-- 
GitLab