Merge pull request #4983 from colemanw/CRM-15842
authorcolemanw <coleman@civicrm.org>
Tue, 20 Jan 2015 18:14:16 +0000 (13:14 -0500)
committercolemanw <coleman@civicrm.org>
Tue, 20 Jan 2015 18:14:16 +0000 (13:14 -0500)
CRM-15842 - Improve custom field multiple record display options

1  2 
CRM/Core/Form.php
CRM/Custom/Form/Group.php

diff --combined CRM/Core/Form.php
index b68f8fef6505e6c6e93a8ab598f7d646cedfa17e,1877210f4ccfcf7be599790fa4f6ed75f471e34c..6556eeecf769364a6330001f74965ca269e272fe
@@@ -23,7 -23,7 +23,7 @@@
   | 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
@@@ -167,7 -167,7 +167,7 @@@ class CRM_Core_Form extends HTML_QuickF
     *
     * @return \CRM_Core_Form
     */
 -  function __construct(
 +  public function __construct(
      $state = NULL,
      $action = CRM_Core_Action::NONE,
      $method = 'post',
     *
     * @return HTML_QuickForm_Element could be an error object
     */
 -  function &add(
 +  public function &add(
      $type, $name, $label = '',
      $attributes = '', $required = FALSE, $extra = NULL
    ) {
      // 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
 +          6,
          ))
      ) {
        $this->ajaxResponse['buttonName'] = str_replace('_qf_' . $this->getAttribute('id') . '_', '', $this->controller->getButtonName());
     *
     * 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
     */
    /**
     * 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
     */
    /**
     * 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
     */
     * @param string $separator
     * @param bool $flipValues
     */
 -  function addCheckBox(
 +  public function addCheckBox(
      $id, $title, $values, $other = NULL,
      $attributes = NULL, $required = NULL,
      $javascriptMethod = NULL,
    public function addCountry($id, $title, $required = NULL, $extra = NULL) {
      $this->addElement('select', $id, $title,
        array(
 -        '' => ts('- select -')
 +        '' => ts('- select -'),
        ) + CRM_Core_PseudoConstant::country(), $extra
      );
      if ($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,
     *   - 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 NULL|integer
 +   * @return NULL|int
     */
    public function getContactID() {
      $tempID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
        $this->assign('selectable', $autoCompleteField['id_field']);
        $this->addEntityRef($autoCompleteField['id_field'], NULL, array(
            'placeholder' => $autoCompleteField['placeholder'],
 -          'api' => $autoCompleteField['api']
 +          'api' => $autoCompleteField['api'],
          ));
  
        CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/AlternateContactSelector.js', 1, 'html-header')
            'country',
            'Country',
            'state_province',
 -          'StateProvince'
 +          'StateProvince',
          ), $elementName),
        'data-callback' => strpos($elementName, 'rovince') ? 'civicrm/ajax/jqState' : 'civicrm/ajax/jqCounty',
        'label' => strpos($elementName, 'rovince') ? ts('State/Province') : ts('County'),
        }
      }
    }
 +
  }
index 806f45272d44a36272c1b4d2465b890b34f519cb,7bcee88ffd3910f552c3e6978905323914ff9b84..8f88a64ac70541e70fd09060704726290517bb3e
@@@ -23,7 -23,7 +23,7 @@@
   | GNU Affero General Public License or the licensing of CiviCRM,     |
   | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
   +--------------------------------------------------------------------+
 -*/
 + */
  
  /**
   *
@@@ -387,7 -387,7 +387,7 @@@ class CRM_Custom_Form_Group extends CRM
        ),
      );
      if (!$this->_isGroupEmpty && !empty($this->_subtypes)) {
-       $buttons[0]['js'] = array('onclick' => "return warnDataLoss()");
+       $buttons[0]['class'] = 'crm-warnDataLoss';
      }
      $this->addButtons($buttons);
  
      }
      return $relName;
    }
 +
  }