Commit 6e343a18 authored by ErikHommel's avatar ErikHommel

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

parents 8ee32cf1 49d39163
......@@ -3,6 +3,7 @@ Version 1.6 (not yet released)
* Updated user interface for better usability.
* Added validation for minimum length.
* Added title column to default data retrieval criteria.
Version 1.5.1
=============
......
......@@ -7,10 +7,10 @@ use CRM_FormProcessor_ExtensionUtil as E;
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProcessor_DAO_FormProcessorDefaultDataInput {
/**
* Function to get values
*
*
* @return array $result found rows with data
* @access public
* @static
......@@ -44,12 +44,12 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
$configuration->set($name, $value);
}
$type->setConfiguration($configuration);
$row['type'] = $type;
}
$row['validators'] = array_values(CRM_FormProcessor_BAO_FormProcessorValidation::getValues(array('entity_id' => $input->id, 'entity' => 'FormProcessorDefaultDataInput')));
$result[$row['id']] = $row;
} else {
//invalid input because no there is no form processor
......@@ -61,8 +61,8 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
/**
* Function to add or update form processor input
*
* @param array $params
*
* @param array $params
* @return array $result
* @access public
* @throws Exception when params is empty
......@@ -73,14 +73,14 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
if (empty($params)) {
throw new Exception('Params can not be empty when adding or updating a form processor input');
}
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'FormProcessorDefaultDataInput', $params['id'], $params);
}
else {
CRM_Utils_Hook::pre('create', 'FormProcessorDefaultDataInput', NULL, $params);
}
$input = new CRM_FormProcessor_BAO_FormProcessorDefaultDataInput();
$fields = self::fields();
foreach ($params as $key => $value) {
......@@ -93,20 +93,20 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
}
$input->save();
self::storeValues($input, $result);
if (!empty($params['id'])) {
CRM_Utils_Hook::post('edit', 'FormProcessorDefaultDataInput', $input->id, $input);
}
else {
CRM_Utils_Hook::post('create', 'FormProcessorDefaultDataInput', $input->id, $input);
}
return $result;
}
/**
* Function to delete a form processor input with id
*
*
* @param int $id
* @throws Exception when $id is empty
* @access public
......@@ -116,18 +116,18 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
if (empty($id)) {
throw new Exception('id can not be empty when attempting to delete a form processor input');
}
CRM_Utils_Hook::pre('delete', 'FormProcessorDefaultDataInput', $id, CRM_Core_DAO::$_nullArray);
$input = new CRM_FormProcessor_BAO_FormProcessorDefaultDataInput();
$input->id = $id;
if ($input->find(true)) {
CRM_FormProcessor_BAO_FormProcessorValidation::deleteWithEntityId('FormProcessorDefaultDataInput', $input->id);
$input->delete();
}
CRM_Utils_Hook::post('delete', 'FormProcessorDefaultDataInput', $id, CRM_Core_DAO::$_nullArray);
return;
}
......@@ -147,6 +147,21 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
}
}
/**
* Public function to generate name from title
*
* @param $title
*
* @return string
* @access public
* @static
*/
public static function buildNameFromTitle($title) {
$titleParts = explode(' ', strtolower($title));
$nameString = implode('_', $titleParts);
return substr($nameString, 0, 80);
}
/**
* Returns whether the name is valid or not
*
......@@ -171,6 +186,6 @@ class CRM_FormProcessor_BAO_FormProcessorDefaultDataInput extends CRM_FormProces
$count = CRM_Core_DAO::singleValueQuery($sql, $params);
return ($count > 0) ? FALSE : TRUE;
}
}
\ No newline at end of file
}
......@@ -43,6 +43,13 @@ class CRM_FormProcessor_DAO_FormProcessorDefaultDataInput extends CRM_Core_DAO {
'required' => true,
'FKApiName' => 'FormProcessorInstance',
),
'title' => array(
'name' => 'title',
'title' => E::ts('Title'),
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 128,
'required' => true,
) ,
'name' => array(
'name' => 'name',
'title' => E::ts('Name'),
......@@ -88,8 +95,9 @@ class CRM_FormProcessor_DAO_FormProcessorDefaultDataInput extends CRM_Core_DAO {
public static function &fieldKeys() {
if (!(self::$_fieldKeys)) {
self::$_fieldKeys = array(
'id' => 'id',
'id' => 'id',
'form_processor_instance_id' => 'form_processor_instance_id',
'title' => 'title',
'name' => 'name',
'type' => 'type',
'is_required' => 'is_required',
......@@ -123,4 +131,4 @@ class CRM_FormProcessor_DAO_FormProcessorDefaultDataInput extends CRM_Core_DAO {
}
return self::$_export;
}
}
\ No newline at end of file
}
......@@ -23,12 +23,17 @@ class CRM_FormProcessor_Upgrader extends CRM_FormProcessor_Upgrader_Base {
}
public function upgrade_1003() {
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_form_processor_action`
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_form_processor_action`
ADD COLUMN `delay` VARCHAR(255) NULL,
ADD COLUMN `delay_configuration` TEXT NULL");
return TRUE;
}
public function upgrade_1004() {
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_form_processor_default_data_input` ADD COLUMN `title` VARCHAR(128) NULL AFTER `form_processor_instance_id`");
return TRUE;
}
/**
* Example: Work with entities usually not available during the install step.
*
......
......@@ -34,7 +34,7 @@
* @return bool
*/
public function validate($input) {
return strlen($input) >= $this->configuration->get('min_length') ? true : false;
}
/**
......
......@@ -134,7 +134,7 @@
if (index < 0) {
action.configuration = angular.copy(actionObject.default_configuration);
}
formProcessorFactory.getFieldList($scope.inputs, $scope.actions, actionObject, $scope.context).
formProcessorFactory.getFieldList($scope.inputs, $scope.actions, action, $scope.context).
then(function (fields) {
var model = {
formProcessor: $scope.formProcessor,
......
<?php
use CRM_FormProcessor_ExtensionUtil as E;
/**
* FormProcessorDefaultDataInput.Converttitletoname API
*
* @param array $params
* @return array API result descriptor
* @see civicrm_api3_create_success
* @see civicrm_api3_create_error
* @throws API_Exception
*/
function civicrm_api3_form_processor_default_data_input_converttitletoname($params) {
$title = $params['title'];
$returnValues['name'] = CRM_FormProcessor_BAO_FormProcessorDefaultInput::buildNameFromTitle($title);
return $returnValues;
}
/**
* FormProcessorInput.Converttitletoname API specification (optional)
* This is used for documentation and validation.
*
* @param array $spec description of fields supported by this API call
* @return void
* @see http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
*/
function _civicrm_api3_form_processor_input_converttitletoname_spec(&$spec) {
$spec['title'] = array(
'title' => E::ts('Title'),
'type' => CRM_Utils_Type::T_STRING,
'api.required' => true
);
}
......@@ -22,6 +22,11 @@ function _civicrm_api3_form_processor_default_data_input_create_spec(&$spec) {
'api.required' => true,
'FKApiName' => 'FormProcessorInstance',
);
$spec['title'] = array(
'title' => E::ts('Title'),
'type' => CRM_Utils_Type::T_STRING,
'api.required' => true
);
$spec['name'] = array(
'title' => E::ts('Name'),
'type' => CRM_Utils_Type::T_STRING,
......
......@@ -39,7 +39,7 @@ In the top part of the form you can enter the general form processor information
* a *name* will be suggested based on the *title* but can be changed if you click on the lock behind the field first!
!!! Note
A *name* can not contain any spaces!
A *name* can not contain any spaces! And should be unique!
* you can specify a detailed description (and it makes sense to do so if you expect to build a few forms!)
* you can tick if the form processor should be enabled (on by default)
......@@ -76,7 +76,7 @@ Initially the part of the form where we can specify actions will look like this:
![Action part of the form](/images/new-action-part.png)
If you click on the action select box you will get a list of actions that are already available because some of the funding organizations needed that action.
As time goes by and more people start using and enhancing the **Action Provider** extension, the list will grow.
As time goes by and more people start using and enhancing the [**Action Provider** extension][actionproviderrepo], the list will grow.
!!! Note "Create your own"
It is possible to develop your own specific actions, or indeed generic ones that others can use too! Check the relevant sections in this guide:
......@@ -111,6 +111,9 @@ And it will be developed in the section [Email Preferences](email-preferences.md
For each of my input fields I can finally specify what data should be loaded here, which should come from the result of my action.
!!! Note "Techie stuff"
On a technical level: If you have enabled default data retrieval it actually generates an API action for the FormProcessorDefaults API entity.
## Output Handler
At the bottom of the form where you edit or create your form processor there is also a bit about an *output handler*:
......@@ -132,5 +135,5 @@ And that is all! A form to be used without coding. Once I saved the form process
So far the basic concept. Obviously the public website part needs to be done too, check the [Example Sign Up Newsletter](sign-up-newsletter.md) section for that part, this section just covers the basis principles.
[actionproviderrepo]:https://lab.civicrm.org/extensions/action-provider
......@@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_form_processor_instance` (
`modified_user_id` INT NULL,
`permission` VARCHAR(255) NOT NULL DEFAULT '',
`status` TINYINT NULL DEFAULT 1,
`source_file` VARCHAR(255) NOT NULL DEFAULT '',
`source_file` VARCHAR(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE INDEX `name_UNIQUE` (`name` ASC)
) ENGINE = InnoDB;
......@@ -59,6 +59,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_form_processor_action` (
CREATE TABLE IF NOT EXISTS `civicrm_form_processor_default_data_input` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`form_processor_instance_id` INT UNSIGNED NOT NULL,
`title` VARCHAR(128) NULL,
`name` VARCHAR(80) NOT NULL,
`type` VARCHAR(80) NOT NULL,
`is_required` TINYINT NULL DEFAULT 0,
......
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