2013-05-10 15:00:13 +02:00
|
|
|
<?php
|
2013-10-15 00:26:23 +02:00
|
|
|
|
2013-05-10 15:00:13 +02:00
|
|
|
/**
|
2013-10-15 00:26:23 +02:00
|
|
|
* Deals with special form handling in CMS, mainly around
|
|
|
|
* {@link PjaxResponseNegotiator}
|
|
|
|
*
|
|
|
|
* @package framework
|
|
|
|
* @subpackage admin
|
2013-05-10 15:00:13 +02:00
|
|
|
*/
|
|
|
|
class CMSForm extends Form {
|
2013-10-03 15:24:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $validationExemptActions = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Always return true if the current form action is exempt from validation
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function validate() {
|
2013-10-14 12:51:54 +02:00
|
|
|
$buttonClicked = $this->buttonClicked();
|
2013-10-03 15:24:19 +02:00
|
|
|
return (
|
2013-10-14 12:51:54 +02:00
|
|
|
($buttonClicked && in_array($buttonClicked->actionName(), $this->getValidationExemptActions()))
|
2013-10-03 15:24:19 +02:00
|
|
|
|| parent::validate()
|
|
|
|
);
|
|
|
|
}
|
2013-05-10 15:00:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Route validation error responses through response negotiator,
|
|
|
|
* so they return the correct markup as expected by the requesting client.
|
|
|
|
*/
|
|
|
|
protected function getValidationErrorResponse() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$negotiator = $this->getResponseNegotiator();
|
2013-10-09 14:27:56 +02:00
|
|
|
|
2013-05-10 15:00:13 +02:00
|
|
|
if($request->isAjax() && $negotiator) {
|
2013-10-09 14:27:56 +02:00
|
|
|
$this->setupFormErrors();
|
|
|
|
$result = $this->forTemplate();
|
|
|
|
|
|
|
|
return $negotiator->respond($request, array(
|
|
|
|
'CurrentForm' => function() use($result) {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
));
|
2013-05-10 15:00:13 +02:00
|
|
|
} else {
|
|
|
|
return parent::getValidationErrorResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-03 15:24:19 +02:00
|
|
|
/**
|
|
|
|
* Set actions that are exempt from validation
|
|
|
|
*
|
|
|
|
* @param array
|
|
|
|
*/
|
|
|
|
public function setValidationExemptActions($actions) {
|
|
|
|
$this->validationExemptActions = $actions;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of actions that are exempt from validation
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getValidationExemptActions() {
|
|
|
|
return $this->validationExemptActions;
|
|
|
|
}
|
|
|
|
|
2013-05-10 15:00:13 +02:00
|
|
|
/**
|
|
|
|
* Sets the response negotiator
|
|
|
|
* @param ResponseNegotiator $negotiator The response negotiator to use
|
|
|
|
* @return Form The current form
|
|
|
|
*/
|
|
|
|
public function setResponseNegotiator($negotiator) {
|
|
|
|
$this->responseNegotiator = $negotiator;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current response negotiator
|
|
|
|
* @return ResponseNegotiator|null
|
|
|
|
*/
|
|
|
|
public function getResponseNegotiator() {
|
|
|
|
return $this->responseNegotiator;
|
|
|
|
}
|
|
|
|
|
2013-10-30 05:08:31 +01:00
|
|
|
}
|