/** * @param CRM_Core_Form $form */ public function buildThankYouBlock(&$form) { $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event'); $attributes['thankyou_text']['click_wysiwyg'] = TRUE; $form->add('text', 'thankyou_title', ts('Title'), $attributes['thankyou_title']); $form->addWysiwyg('thankyou_text', ts('Introductory Text'), $attributes['thankyou_text']); // FIXME: This hack forces height of editor to 175px. Need to modify QF classes for editors to allow passing // explicit height and width. $footerAttribs = array('rows' => 2, 'cols' => 40, 'click_wysiwyg' => TRUE); $form->addWysiwyg('thankyou_footer_text', ts('Footer Text'), $footerAttribs); }
/** * This function for building custom fields. * * @param CRM_Core_Form $qf * Form object (reference). * @param string $elementName * Name of the custom field. * @param int $fieldId * @param bool $inactiveNeeded * -deprecated. * @param bool $useRequired * True if required else false. * @param bool $search * True if used for search else false. * @param string $label * Label for custom field. * */ public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded = FALSE, $useRequired = TRUE, $search = FALSE, $label = NULL) { $field = self::getFieldObject($fieldId); $widget = $field->html_type; // Custom field HTML should indicate group+field name $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id); $dataCrmCustomVal = $groupName . ':' . $field->name; $dataCrmCustomAttr = 'data-crm-custom="' . $dataCrmCustomVal . '"'; $field->attributes .= $dataCrmCustomAttr; // Fixed for Issue CRM-2183 if ($widget == 'TextArea' && $search) { $widget = 'Text'; } $placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -')); // FIXME: Why are select state/country separate widget types? $isSelect = in_array($widget, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country', 'AdvMulti-Select', 'CheckBox', 'Radio')); if ($isSelect) { $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array('field' => "custom_{$fieldId}", 'context' => $search ? 'search' : 'create'), array())); // Consolidate widget types to simplify the below switch statement if ($search || $widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE) { $widget = 'Select'; } $selectAttributes = array('data-crm-custom' => $dataCrmCustomVal, 'class' => 'crm-select2'); // Search field is always multi-select if ($search || strpos($field->html_type, 'Multi') !== FALSE) { $selectAttributes['class'] .= ' huge'; $selectAttributes['multiple'] = 'multiple'; $selectAttributes['placeholder'] = $placeholder; } // Add data for popup link. Normally this is handled by CRM_Core_Form->addSelect if ($field->option_group_id && !$search && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM')) { $selectAttributes += array('data-api-entity' => 'contact', 'data-api-field' => 'custom_' . $field->id, 'data-option-edit-path' => 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $field->option_group_id)); } } if (!isset($label)) { $label = $field->label; } /** * at some point in time we might want to split the below into small functions **/ switch ($widget) { case 'Text': case 'Link': if ($field->is_search_range && $search) { $qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $field->attributes); $qf->add('text', $elementName . '_to', ts('To'), $field->attributes); } else { $element =& $qf->add('text', $elementName, $label, $field->attributes, $useRequired && !$search); } break; case 'TextArea': $attributes = $dataCrmCustomAttr; if ($field->note_rows) { $attributes .= 'rows=' . $field->note_rows; } else { $attributes .= 'rows=4'; } if ($field->note_columns) { $attributes .= ' cols=' . $field->note_columns; } else { $attributes .= ' cols=60'; } if ($field->text_length) { $attributes .= ' maxlength=' . $field->text_length; } $element =& $qf->add('textarea', $elementName, $label, $attributes, $useRequired && !$search); break; case 'Select Date': if ($field->is_search_range && $search) { $qf->addDate($elementName . '_from', $label . ' - ' . ts('From'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal)); $qf->addDate($elementName . '_to', ts('To'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal)); } else { $required = $useRequired && !$search; $qf->addDate($elementName, $label, $required, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal)); } break; case 'Radio': $choice = array(); foreach ($options as $v => $l) { $choice[] = $qf->createElement('radio', NULL, '', $l, (string) $v, $field->attributes); } $group = $qf->addGroup($choice, $elementName, $label); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } else { $group->setAttribute('allowClear', TRUE); } break; // For all select elements // For all select elements case 'Select': if (empty($selectAttributes['multiple'])) { $options = array('' => $placeholder) + $options; } $qf->add('select', $elementName, $label, $options, $useRequired && !$search, $selectAttributes); // Add and/or option for fields that store multiple values if ($search && self::isSerialized($field)) { $operators = array($qf->createElement('radio', NULL, '', ts('Any'), 'or', array('title' => ts('Results may contain any of the selected options'))), $qf->createElement('radio', NULL, '', ts('All'), 'and', array('title' => ts('Results must have all of the selected options')))); $qf->addGroup($operators, $elementName . '_operator'); $qf->setDefaults(array($elementName . '_operator' => 'or')); } break; case 'AdvMulti-Select': $include =& $qf->addElement('advmultiselect', $elementName, $label, $options, array('size' => 5, 'style' => '', 'class' => 'advmultiselect', 'data-crm-custom' => $dataCrmCustomVal)); $include->setButtonAttributes('add', array('value' => ts('Add >>'))); $include->setButtonAttributes('remove', array('value' => ts('<< Remove'))); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'CheckBox': $check = array(); foreach ($options as $v => $l) { $check[] =& $qf->addElement('advcheckbox', $v, NULL, $l, array('data-crm-custom' => $dataCrmCustomVal)); } $qf->addGroup($check, $elementName, $label); if ($useRequired && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'File': // we should not build upload file in search mode if ($search) { return; } $qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, $useRequired && !$search); $qf->addUploadElement($elementName); break; case 'RichTextEditor': $attributes = array('rows' => $field->note_rows, 'cols' => $field->note_columns, 'data-crm-custom' => $dataCrmCustomVal); if ($field->text_length) { $attributes['maxlength'] = $field->text_length; } $qf->addWysiwyg($elementName, $label, $attributes, $search); break; case 'Autocomplete-Select': static $customUrls = array(); // Fixme: why is this a string in the first place?? $attributes = array(); if ($field->attributes) { foreach (explode(' ', $field->attributes) as $at) { if (strpos($at, '=')) { list($k, $v) = explode('=', $at); $attributes[$k] = trim($v, ' "'); } } } if ($field->data_type == 'ContactReference') { $attributes['class'] = (isset($attributes['class']) ? $attributes['class'] . ' ' : '') . 'crm-form-contact-reference huge'; $attributes['data-api-entity'] = 'contact'; $qf->add('text', $elementName, $label, $attributes, $useRequired && !$search); $urlParams = "context=customfield&id={$field->id}"; $customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/contactref', $urlParams, FALSE, NULL, FALSE); } else { // FIXME: This won't work with customFieldOptions hook $attributes += array('entity' => 'option_value', 'placeholder' => $placeholder, 'multiple' => $search, 'api' => array('params' => array('option_group_id' => $field->option_group_id))); $qf->addEntityRef($elementName, $label, $attributes, $useRequired && !$search); } $qf->assign('customUrls', $customUrls); break; } switch ($field->data_type) { case 'Int': // integers will have numeric rule applied to them. if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must be an integer (whole number).', array(1 => $label)), 'integer'); $qf->addRule($elementName . '_to', ts('%1 To must be an integer (whole number).', array(1 => $label)), 'integer'); } elseif ($widget == 'Text') { $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'integer'); } break; case 'Float': if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); $qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); } elseif ($widget == 'Text') { $qf->addRule($elementName, ts('%1 must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); } break; case 'Money': if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money'); $qf->addRule($elementName . '_to', ts('%1 To must in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money'); } elseif ($widget == 'Text') { $qf->addRule($elementName, ts('%1 must be in proper money format. (decimal point/comma/space is allowed).', array(1 => $label)), 'money'); } break; case 'Link': $element->setAttribute('onfocus', "if (!this.value) {this.value='http://';}"); $element->setAttribute('onblur', "if (this.value == 'http://') {this.value='';}"); $element->setAttribute('class', "url"); $qf->addRule($elementName, ts('Enter a valid Website.'), 'wikiURL'); break; } if ($field->is_view && !$search) { $qf->freeze($elementName); } }
/** * Build the form object. * * @param CRM_Core_Form $form * Form object. * * @return void */ public static function buildFriendForm($form) { $form->addElement('checkbox', 'tf_is_active', ts('Tell a Friend enabled?'), NULL, array('onclick' => "friendBlock(this)")); // name $form->add('text', 'tf_title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'title'), TRUE); // intro-text and thank-you text $form->addWysiwyg('intro', ts('Introduction'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'intro'), TRUE); $form->add('textarea', 'suggested_message', ts('Suggested Message'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'suggested_message'), FALSE); $form->add('text', 'general_link', ts('Info Page Link'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'general_link')); $form->add('text', 'tf_thankyou_title', ts('Thank-you Title'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'thankyou_title'), TRUE); $form->addWysiwyg('tf_thankyou_text', ts('Thank-you Message'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'thankyou_text'), TRUE); if ($form->_friendId) { // CRM-14200 the i18n dialogs need this for translation $form->assign('friendId', $form->_friendId); } }