* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* @file
- */
-
-/**
- * @defgroup Actions Action done on pages
+ * @ingroup Actions
*/
/**
* An action which shows a form and does something based on the input from the form
+ *
+ * @ingroup Actions
*/
abstract class FormAction extends Action {
/**
* Get an HTMLForm descriptor array
- * @return Array
+ * @return array
*/
abstract protected function getFormFields();
/**
* Add pre- or post-text to the form
- * @return String HTML which will be sent to $form->addPreText()
+ * @return string HTML which will be sent to $form->addPreText()
*/
protected function preText() {
return '';
/**
* Play with the HTMLForm if you need to more substantially
- * @param $form HTMLForm
+ * @param HTMLForm $form
*/
protected function alterForm( HTMLForm $form ) {
}
* Process the form on POST submission. If you return false from getFormFields(),
* this will obviously never be reached. If you don't want to do anything with the
* form, just return false here
- * @param $data Array
- * @return Bool|Array true for success, false for didn't-try, array of errors on failure
+ * @param array $data
+ * @return bool|array True for success, false for didn't-try, array of errors on failure
*/
abstract public function onSubmit( $data );
$this->onSuccess();
}
}
-
- /**
- * @see Action::execute()
- *
- * @param $data array|null
- * @param $captureErrors bool
- * @throws ErrorPageError|Exception
- * @return bool
- */
- public function execute( array $data = null, $captureErrors = true ) {
- try {
- // Set a new context so output doesn't leak.
- $this->context = clone $this->getContext();
-
- // This will throw exceptions if there's a problem
- $this->checkCanExecute( $this->getUser() );
-
- $fields = array();
- foreach ( $this->fields as $key => $params ) {
- if ( isset( $data[$key] ) ) {
- $fields[$key] = $data[$key];
- } elseif ( isset( $params['default'] ) ) {
- $fields[$key] = $params['default'];
- } else {
- $fields[$key] = null;
- }
- }
- $status = $this->onSubmit( $fields );
- if ( $status === true ) {
- // This might do permanent stuff
- $this->onSuccess();
- return true;
- } else {
- return false;
- }
- }
- catch ( ErrorPageError $e ) {
- if ( $captureErrors ) {
- return false;
- } else {
- throw $e;
- }
- }
- }
}