Expose form field objects in HTMLForm
authorGergő Tisza <gtisza@wikimedia.org>
Mon, 22 Aug 2016 22:24:41 +0000 (22:24 +0000)
committerGergő Tisza <gtisza@wikimedia.org>
Mon, 22 Aug 2016 22:25:54 +0000 (22:25 +0000)
Change-Id: Id22c5b9da154d67948ff2b91702a256c25718312

includes/htmlform/HTMLForm.php

index ff37e24..3c88594 100644 (file)
@@ -354,6 +354,26 @@ class HTMLForm extends ContextSource {
                $this->mFieldTree = $loadedDescriptor;
        }
 
+       /**
+        * @param string $fieldname
+        * @return bool
+        */
+       public function hasField( $fieldname ) {
+               return isset( $this->mFlatFields[$fieldname] );
+       }
+
+       /**
+        * @param string $fieldname
+        * @return HTMLFormField
+        * @throws DomainException on invalid field name
+        */
+       public function getField( $fieldname ) {
+               if ( !$this->hasField( $fieldname ) ) {
+                       throw new DomainException( __METHOD__ . ': no field named ' . $fieldname );
+               }
+               return $this->mFlatFields[$fieldname];
+       }
+
        /**
         * Set format in which to display the form
         *