Commit d1cb8291 authored by jaapjansma's avatar jaapjansma

Merge branch 'master' of lab.civicrm.org:extensions/form-processor

parents fd1de728 9293c52a
......@@ -36,6 +36,7 @@ class CRM_FormProcessor_Form_RunFormProcessor extends CRM_Core_Form {
public function buildQuickForm() {
$this->add('hidden', '_qf_formProcessorName');
$this->setDefaults(['_qf_formProcessorName' => $this->formProcessorName]);
$formProcessor = civicrm_api3('FormProcessorInstance', 'getsingle', ['name' => $this->formProcessorName]);
$defaultFields = civicrm_api3('FormProcessorDefaults', 'getfields', ['api_action' => $this->formProcessorName]);
$this->defaultFields = $defaultFields['values'];
$defaultFieldNames = [];
......@@ -56,6 +57,7 @@ class CRM_FormProcessor_Form_RunFormProcessor extends CRM_Core_Form {
}
$defaultFieldNames[] = $this->formProcessorName.'_default_'.$field['name'];
}
$this->assign('enableDefault', $formProcessor['enable_default_data']);
$this->assign('defaultFieldNames', $defaultFieldNames);
$fields = civicrm_api3('FormProcessor', 'getfields', ['api_action' => $this->formProcessorName]);
......@@ -177,7 +179,7 @@ class CRM_FormProcessor_Form_RunFormProcessor extends CRM_Core_Form {
$params['version'] = 3;
$result = civicrm_api('FormProcessor', $this->formProcessorName, $params);
$this->assign('result_json', json_encode($result, JSON_PRETTY_PRINT));
if (!isset($default['is_error']) || !$default['is_error']) {
if (!isset($result['is_error']) || !$result['is_error']) {
$this->clearForm();
}
}
......
......@@ -139,7 +139,7 @@ class FormProcessorDefaults extends FormProcessor implements API_ProviderInterfa
// Check the validations on the input.
if (isset($params[$input['name']]) && $params[$input['name']] != "") {
foreach ($input['validators'] as $validator) {
if (!$validator['validator']->validate($params[$input['name']])) {
if (!$validator['validator']->validate($params[$input['name']], $inputType)) {
throw new \API_Exception($validator['validator']->getInvalidMessage() . ' (Parameter ' . $input['name'] . ')');
}
}
......
......@@ -4,49 +4,50 @@
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
namespace Civi\FormProcessor\Validation;
use \Civi\FormProcessor\Config\ConfigurationBag;
use \Civi\FormProcessor\Config\Specification;
use \Civi\FormProcessor\Config\SpecificationBag;
use CRM_FormProcessor_ExtensionUtil as E;
abstract class AbstractValidator implements \JsonSerializable {
/**
* @var ConfigurationBag
*/
protected $configuration;
/**
* @var ConfigurationBag
*/
protected $defaultConfiguration;
/**
* Returns the name of the validator.
*
*
* @return string
*/
abstract public function getName();
/**
* Returns the label of the validator.
*
*
* @return string
*/
abstract public function getLabel();
/**
* Validate the input.
*
*
* @param mixed $input
* @param \Civi\FormProcessor\Type\AbstractType $inputType
* @return bool
*/
abstract public function validate($input, $inputType);
public function __construct() {
$this->configuration = new ConfigurationBag();
$this->defaultConfiguration = new ConfigurationBag();
......@@ -58,16 +59,16 @@
}
}
}
/**
* Get the configuration specification
*
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag();
}
/**
* @return bool;
*/
......@@ -77,31 +78,31 @@
}
return SpecificationBag::validate($this->configuration, $this->getConfigurationSpecification());
}
/**
* @return ConfigurationBag
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* @return ConfigurationBag
*/
public function getDefaultConfiguration() {
return $this->defaultConfiguration;
}
/**
* Returns the invalid message.
*
*
* @return string
*/
public function getInvalidMessage() {
return E::ts('Invalid %1', array(1=>$this->getLabel()));
}
/**
* @param ConfigurationBag $configuration
*/
......@@ -109,7 +110,7 @@
$this->configuration = $configuration;
return $this;
}
public function toArray() {
return array(
'name' => $this->getName(),
......@@ -119,9 +120,9 @@
'configuration' => $this->getConfiguration()->toArray(),
);
}
public function jsonSerialize() {
return $this->toArray();
}
}
......@@ -85,7 +85,7 @@ class DateValidator extends AbstractValidator {
* Validate the input.
*
* @param mixed $input
*
* @param \Civi\FormProcessor\Type\AbstractType $inputType
* @return bool
*/
public function validate($input, $inputType) {
......
......@@ -4,39 +4,40 @@
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
namespace Civi\FormProcessor\Validation;
use \Civi\FormProcessor\Validation\AbstractValidator;
use CRM_FormProcessor_ExtensionUtil as E;
class EmailValidator extends AbstractValidator {
const PATTERN_LOOSE = '/^.+\@\S+\.\S+$/';
public function getLabel() {
return E::ts('E-mail');
}
/**
* Returns the name of the validator.
*
*
* @return string
*/
public function getName() {
return 'email';
}
/**
* Validate the input.
*
*
* @param mixed $input
* @param \Civi\FormProcessor\Type\AbstractType $inputType
* @return bool
*/
public function validate($input, $inputType) {
$pattern = EmailValidator::PATTERN_LOOSE;
return preg_match($pattern, $input);
}
}
......@@ -39,6 +39,7 @@
* Validate the input.
*
* @param mixed $input
* @param \Civi\FormProcessor\Type\AbstractType $inputType
* @return bool
*/
public function validate($input, $inputType) {
......@@ -52,7 +53,7 @@
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new Specification('max_value', 'Integer', E::ts('Maximum value'), true)
new Specification('max_value', 'Float', E::ts('Maximum value'), true)
));
}
......
......@@ -31,6 +31,7 @@
* Validate the input.
*
* @param mixed $input
* @param \Civi\FormProcessor\Type\AbstractType $inputType
* @return bool
*/
public function validate($input, $inputType) {
......
......@@ -39,6 +39,7 @@
* Validate the input.
*
* @param mixed $input
* @param \Civi\FormProcessor\Type\AbstractType $inputType
* @return bool
*/
public function validate($input, $inputType) {
......@@ -52,7 +53,7 @@
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new Specification('min_value', 'Integer', E::ts('Minimum value'), true)
new Specification('min_value', 'Float', E::ts('Minimum value'), true)
));
}
......
{crmScope extensionKey='form-processor'}
{if (count($defaultFieldNames))}
{if ($enableDefault)}
<div class="crm-form-block">
<div class="crm-accordion-wrapper crm-advanced_search_form-accordion">
<div class="crm-accordion-header crm-master-accordion-header">{ts}Retrieve default data{/ts}</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment