| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
* This is our base form. It is part of the Form/Controller/StateMachine
private $_chainSelectFields = array();
/**
- * Constructor for the basic form page
+ * Constructor for the basic form page.
*
* We should not use QuickForm directly. This class provides a lot
* of default convenient functions, rules and buttons
*
* @return \CRM_Core_Form
*/
- function __construct(
+ public function __construct(
$state = NULL,
$action = CRM_Core_Action::NONE,
$method = 'post',
*/
public function registerRules() {
static $rules = array(
- 'title', 'longTitle', 'variable', 'qfVariable',
- 'phone', 'integer', 'query',
- 'url', 'wikiURL',
- 'domain', 'numberOfDigit',
- 'date', 'currentDate',
- 'asciiFile', 'htmlFile', 'utf8File',
- 'objectExists', 'optionExists', 'postalCode', 'money', 'positiveInteger',
- 'xssString', 'fileExists', 'autocomplete', 'validContact',
+ 'title',
+ 'longTitle',
+ 'variable',
+ 'qfVariable',
+ 'phone',
+ 'integer',
+ 'query',
+ 'url',
+ 'wikiURL',
+ 'domain',
+ 'numberOfDigit',
+ 'date',
+ 'currentDate',
+ 'asciiFile',
+ 'htmlFile',
+ 'utf8File',
+ 'objectExists',
+ 'optionExists',
+ 'postalCode',
+ 'money',
+ 'positiveInteger',
+ 'xssString',
+ 'fileExists',
+ 'autocomplete',
+ 'validContact',
);
foreach ($rules as $rule) {
*
* @return HTML_QuickForm_Element could be an error object
*/
- function &add(
+ public function &add(
$type, $name, $label = '',
$attributes = '', $required = FALSE, $extra = NULL
) {
$this->postProcessHook();
// Respond with JSON if in AJAX context (also support legacy value '6')
- if ($allowAjax && !empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], array(CRM_Core_Smarty::PRINT_JSON, 6))) {
+ if ($allowAjax && !empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], array(
+ CRM_Core_Smarty::PRINT_JSON,
+ 6,
+ ))
+ ) {
$this->ajaxResponse['buttonName'] = str_replace('_qf_' . $this->getAttribute('id') . '_', '', $this->controller->getButtonName());
$this->ajaxResponse['action'] = $this->_action;
if (isset($this->_id) || isset($this->id)) {
}
/**
- * The postProcess hook is typically called by the framework
+ * The postProcess hook is typically called by the framework.
* However in a few cases, the form exits or redirects early in which
* case it needs to call this function so other modules can do the needful
* Calling this function directly should be avoided if possible. In general a
*
* access public
*
- * @return array
+ * @return array|NULL
* reference to the array of default values
*/
public function setDefaultValues() {
+ return NULL;
}
/**
/**
* Performs the server side validation
* @since 1.0
- * @return boolean
+ * @return bool
* true if no error found
* @throws HTML_QuickForm_Error
*/
//Set html data-attribute to enable warning user of unsaved changes
if ($this->unsavedChangesWarn === TRUE
- || (!isset($this->unsavedChangesWarn)
- && ($this->_action & CRM_Core_Action::ADD || $this->_action & CRM_Core_Action::UPDATE)
- )
- ) {
+ || (!isset($this->unsavedChangesWarn)
+ && ($this->_action & CRM_Core_Action::ADD || $this->_action & CRM_Core_Action::UPDATE)
+ )
+ ) {
$this->setAttribute('data-warn-changes', 'true');
}
}
/**
* Add default Next / Back buttons
*
- * @param array array of associative arrays in the order in which the buttons should be
- * displayed. The associate array has 3 fields: 'type', 'name' and 'isDefault'
- * The base form class will define a bunch of static arrays for commonly used
- * formats
+ * @param array $params
+ * Array of associative arrays in the order in which the buttons should be
+ * displayed. The associate array has 3 fields: 'type', 'name' and 'isDefault'
+ * The base form class will define a bunch of static arrays for commonly used
+ * formats.
*
* @return void
*/
foreach ($params as $button) {
$attrs = array('class' => 'crm-form-submit') + (array) CRM_Utils_Array::value('js', $button);
+ if (!empty($button['class'])) {
+ $attrs['class'] .= ' ' . $button['class'];
+ }
+
if (!empty($button['isDefault'])) {
$attrs['class'] .= ' default';
}
/**
* Setter function for options
*
- * @param mixed
+ * @param mixed $options
*
* @return void
*/
/**
* Boolean function to determine if this is a one form page
*
- * @return boolean
+ * @return bool
*/
public function isSimpleForm() {
return $this->_state->getType() & (CRM_Core_State::START | CRM_Core_State::FINISH);
/**
* Setter function for Form Action
*
- * @param string
+ * @param string $action
*
* @return void
*/
$tplname = $ext->getTemplatePath(CRM_Utils_System::getClassName($this)) . DIRECTORY_SEPARATOR . $filename;
}
else {
- $tplname = str_replace('_',
- DIRECTORY_SEPARATOR,
- CRM_Utils_System::getClassName($this)
+ $tplname = strtr(
+ CRM_Utils_System::getClassName($this),
+ array(
+ '_' => DIRECTORY_SEPARATOR,
+ '\\' => DIRECTORY_SEPARATOR,
+ )
) . '.tpl';
}
return $tplname;
/**
* Store the variable with the value in the form scope
*
- * @param string name : name of the variable
- * @param mixed value : value of the variable
- *
+ * @param string $name
+ * Name of the variable.
+ * @param mixed $value
+ * Value of the variable.
*
* @return void
*/
/**
* Get the variable from the form scope
*
- * @param string name : name of the variable
- *
+ * @param string $name
+ * Name of the variable
*
* @return mixed
*/
*/
public function addYesNo($id, $title, $allowClear = FALSE, $required = NULL, $attributes = array()) {
$attributes += array('id_suffix' => $id);
- $choice = array();
+ $choice = array();
$choice[] = $this->createElement('radio', NULL, '11', ts('Yes'), '1', $attributes);
$choice[] = $this->createElement('radio', NULL, '11', ts('No'), '0', $attributes);
* @param string $separator
* @param bool $flipValues
*/
- function addCheckBox(
+ public function addCheckBox(
$id, $title, $values, $other = NULL,
$attributes = NULL, $required = NULL,
$javascriptMethod = NULL,
'editor_id'
);
$editor = strtolower(CRM_Utils_Array::value($editorID,
- CRM_Core_OptionGroup::values('wysiwyg_editor')
- ));
+ CRM_Core_OptionGroup::values('wysiwyg_editor')
+ ));
if (!$editor || $forceTextarea) {
$editor = 'textarea';
}
public function addCountry($id, $title, $required = NULL, $extra = NULL) {
$this->addElement('select', $id, $title,
array(
- '' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $extra
+ '' => ts('- select -'),
+ ) + CRM_Core_PseudoConstant::country(), $extra
);
if ($required) {
$this->addRule($id, ts('Please select %1', array(1 => $title)), 'required');
/**
* Add date
- * @param string $name
- * Name of the element.
- * @param string $label
- * Label of the element.
- * @param array $attributes
- * Key / value pair.
*
+ * @code
* // if you need time
* $attributes = array(
* 'addTime' => true,
* 'formatType' => 'relative' or 'birth' etc check advanced date settings
* );
+ * @endcode
+ *
+ * @param string $name
+ * Name of the element.
+ * @param string $label
+ * Label of the element.
* @param bool $required
* True if required.
+ * @param array $attributes
+ * Key / value pair.
*/
public function addDate($name, $label, $required = FALSE, $attributes = NULL) {
if (!empty($attributes['formatType'])) {
/**
* Add a currency and money element to the form
*/
- function addMoney(
+ public function addMoney(
$name,
$label,
$required = FALSE,
/**
* Add currency element to the form
*/
- function addCurrency(
+ public function addCurrency(
$name = 'currency',
$label = NULL,
$required = TRUE,
* @param string $label
* @param array $props
* Mix of html and widget properties, including:.
- * - select - params to give to select2 widget
- * - entity - defaults to contact
- * - create - can the user create a new entity on-the-fly?
+ * - select - params to give to select2 widget
+ * - entity - defaults to contact
+ * - create - can the user create a new entity on-the-fly?
* Set to TRUE if entity is contact and you want the default profiles,
* or pass in your own set of links. @see CRM_Core_BAO_UFGroup::getCreateLinks for format
* note that permissions are checked automatically
- * - api - array of settings for the getlist api wrapper
+ * - api - array of settings for the getlist api wrapper
* note that it accepts a 'params' setting which will be passed to the underlying api
- * - placeholder - string
- * - multiple - bool
- * - class, etc. - other html properties
+ * - placeholder - string
+ * - multiple - bool
+ * - class, etc. - other html properties
* @param bool $required
*
* @return HTML_QuickForm_Element
if (!empty($params[$fieldName])) {
$params[$fieldName] = CRM_Utils_Date::isoToMysql(
CRM_Utils_Date::processDate(
- $params[$fieldName],
- CRM_Utils_Array::value("{$fieldName}_time", $params), TRUE)
+ $params[$fieldName],
+ CRM_Utils_Array::value("{$fieldName}_time", $params), TRUE)
);
}
else {
/**
* Get contact if for a form object. Prioritise
- * - cid in URL if 0 (on behalf on someoneelse)
+ * - cid in URL if 0 (on behalf on someoneelse)
* (@todo consider setting a variable if onbehalf for clarity of downstream 'if's
- * - logged in user id if it matches the one in the cid in the URL
- * - contact id validated from a checksum from a checksum
- * - cid from the url if the caller has ACL permission to view
- * - fallback is logged in user (or ? NULL if no logged in user) (@todo wouldn't 0 be more intuitive?)
+ * - logged in user id if it matches the one in the cid in the URL
+ * - contact id validated from a checksum from a checksum
+ * - cid from the url if the caller has ACL permission to view
+ * - fallback is logged in user (or ? NULL if no logged in user) (@todo wouldn't 0 be more intuitive?)
*
- * @return mixed NULL|integer
+ * @return NULL|int
*/
public function getContactID() {
$tempID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
* Ids of profiles that are on the form (to be autofilled).
* @param array $autoCompleteField
*
- * - name_field
- * - id_field
- * - url (for ajax lookup)
+ * - name_field
+ * - id_field
+ * - url (for ajax lookup)
*
* @todo add data attributes so we can deal with multiple instances on a form
*/
public function addAutoSelector($profiles = array(), $autoCompleteField = array()) {
$autoCompleteField = array_merge(array(
- 'id_field' => 'select_contact_id',
- 'placeholder' => ts('Select someone else ...'),
- 'show_hide' => TRUE,
- 'api' => array('params' => array('contact_type' => 'Individual')),
- ), $autoCompleteField);
+ 'id_field' => 'select_contact_id',
+ 'placeholder' => ts('Select someone else ...'),
+ 'show_hide' => TRUE,
+ 'api' => array('params' => array('contact_type' => 'Individual')),
+ ), $autoCompleteField);
if ($this->canUseAjaxContactLookups()) {
$this->assign('selectable', $autoCompleteField['id_field']);
- $this->addEntityRef($autoCompleteField['id_field'], NULL, array('placeholder' => $autoCompleteField['placeholder'], 'api' => $autoCompleteField['api']));
+ $this->addEntityRef($autoCompleteField['id_field'], NULL, array(
+ 'placeholder' => $autoCompleteField['placeholder'],
+ 'api' => $autoCompleteField['api'],
+ ));
CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/AlternateContactSelector.js', 1, 'html-header')
- ->addSetting(array(
- 'form' => array('autocompletes' => $autoCompleteField),
- 'ids' => array('profile' => $profiles),
- ));
+ ->addSetting(array(
+ 'form' => array('autocompletes' => $autoCompleteField),
+ 'ids' => array('profile' => $profiles),
+ ));
}
}
*/
public function canUseAjaxContactLookups() {
if (0 < (civicrm_api3('contact', 'getcount', array('check_permissions' => 1))) &&
- CRM_Core_Permission::check(array(array('access AJAX API', 'access CiviCRM')))) {
+ CRM_Core_Permission::check(array(array('access AJAX API', 'access CiviCRM')))
+ ) {
return TRUE;
}
}
* that small pieces of duplication are not being refactored into separate functions because their only shared parent
* is this form. Inserting a class FrontEndForm.php between the contribution & event & this class would allow functions like this
* and a dozen other small ones to be refactored into a shared parent with the reduction of much code duplication
+ *
+ * @param $onlinePaymentProcessorEnabled
*/
public function addCIDZeroOptions($onlinePaymentProcessorEnabled) {
$this->assign('nocid', TRUE);
*/
public function addChainSelect($elementName, $settings = array()) {
$props = $settings += array(
- 'control_field' => str_replace(array('state_province', 'StateProvince', 'county', 'County'), array('country', 'Country', 'state_province', 'StateProvince'), $elementName),
+ 'control_field' => str_replace(array('state_province', 'StateProvince', 'county', 'County'), array(
+ 'country',
+ 'Country',
+ 'state_province',
+ 'StateProvince',
+ ), $elementName),
'data-callback' => strpos($elementName, 'rovince') ? 'civicrm/ajax/jqState' : 'civicrm/ajax/jqCounty',
'label' => strpos($elementName, 'rovince') ? ts('State/Province') : ts('County'),
'data-empty-prompt' => strpos($elementName, 'rovince') ? ts('Choose country first') : ts('Choose state first'),
}
}
}
+
}