Add `IFormDocument::(get|has)Button()`
authorMatthias Schmidt <gravatronics@live.com>
Sat, 6 Apr 2019 10:25:38 +0000 (12:25 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 6 Apr 2019 10:25:38 +0000 (12:25 +0200)
See #2509

wcfsetup/install/files/lib/system/form/builder/DialogFormDocument.class.php
wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php
wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php

index f9937a92f987ae0fba2136e9ffb022760580d199..e4b2b90ecb3d047ef07916b06f8ff19d58b90f2d 100644 (file)
@@ -51,7 +51,7 @@ class DialogFormDocument extends FormDocument {
        protected function createDefaultButton() {
                parent::createDefaultButton();
                
-               $this->getButtons()['submitButton']->attribute('data-type', 'submit');
+               $this->getButton('submitButton')->attribute('data-type', 'submit');
                
                if ($this->isCancelable()) {
                        $this->addButton(
index b6416492d731b556ab184812ccf809efa5a10949..9116846ef5879fbf6c2e749c229eaa337cbe29f3 100644 (file)
@@ -299,13 +299,24 @@ class FormDocument implements IFormDocument {
                return $this->action;
        }
        
+       /**
+        * @inheritDoc
+        */
+       public function getButton($buttonId) {
+               if (!$this->hasButton($buttonId)) {
+                       throw new \InvalidArgumentException("Unknown button with id '{$buttonId}'.");
+               }
+               
+               return $this->buttons[$buttonId];
+       }
+       
        /**
         * @inheritDoc
         */
        public function getButtons() {
                return $this->buttons;
        }
-
+       
        /**
         * @inheritDoc
         */
@@ -438,6 +449,13 @@ class FormDocument implements IFormDocument {
                return $this->successMessage;
        }
        
+       /**
+        * @inheritDoc
+        */
+       public function hasButton($buttonId) {
+               return isset($this->buttons[$buttonId]);
+       }
+       
        /**
         * @inheritDoc
         */
index 8da4e81567b4601726fc390b77e840dd1b579dbc..0a9df5b0c10e3042c66e29051e5516fbb305ef29 100644 (file)
@@ -111,6 +111,16 @@ interface IFormDocument extends IFormParentNode {
         */
        public function getAction();
        
+       /**
+        * Returns the button with the given id.
+        * 
+        * @param       string          $buttonId       id of requested button
+        * @return      IFormButton
+        * 
+        * @throws      \InvalidArgumentException       if no such button exists
+        */
+       public function getButton($buttonId);
+       
        /**
         * Returns the buttons registered for this form document.
         * 
@@ -210,6 +220,14 @@ interface IFormDocument extends IFormParentNode {
         */
        public function getSuccessMessage();
        
+       /**
+        * Returns `true` if a button with the given id exists and `false` otherwise.
+        *
+        * @param       string          $buttonId       id of checked button
+        * @return      boolean
+        */
+       public function hasButton($buttonId);
+       
        /**
         * Returns `true` if the default button is added to the form during in the `build()` method
         * and `false` otherwise.