本文整理汇总了PHP中CRM_Core_Form::freeze方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Form::freeze方法的具体用法?PHP CRM_Core_Form::freeze怎么用?PHP CRM_Core_Form::freeze使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Form
的用法示例。
在下文中一共展示了CRM_Core_Form::freeze方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* Build form.
*
* @param CRM_Core_Form $form
*/
public static function buildForm(&$form)
{
// We should not build form elements in dashlet mode.
if ($form->_section) {
return;
}
// Check role based permission.
$instanceID = $form->getVar('_id');
if ($instanceID && !CRM_Report_Utils_Report::isInstanceGroupRoleAllowed($instanceID)) {
$url = CRM_Utils_System::url('civicrm/report/list', 'reset=1');
CRM_Core_Error::statusBounce(ts('You do not have permission to access this report.'), $url);
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Report_DAO_ReportInstance');
$form->add('text', 'title', ts('Report Title'), $attributes['title']);
$form->add('text', 'description', ts('Report Description'), $attributes['description']);
$form->add('text', 'email_subject', ts('Subject'), $attributes['email_subject']);
$form->add('text', 'email_to', ts('To'), $attributes['email_to']);
$form->add('text', 'email_cc', ts('CC'), $attributes['email_subject']);
$form->add('number', 'row_count', ts('Limit Dashboard Results'), array('class' => 'four', 'min' => 1));
$form->add('textarea', 'report_header', ts('Report Header'), $attributes['header']);
$form->add('textarea', 'report_footer', ts('Report Footer'), $attributes['footer']);
$form->addElement('checkbox', 'is_navigation', ts('Include Report in Navigation Menu?'), NULL, array('onclick' => "return showHideByValue('is_navigation','','navigation_menu','table-row','radio',false);"));
$form->addElement('select', 'view_mode', ts('Configure link to...'), array('view' => ts('View Results'), 'criteria' => ts('Show Criteria')));
$form->addElement('checkbox', 'addToDashboard', ts('Available for Dashboard?'));
$form->add('number', 'cache_minutes', ts('Cache dashlet for'), array('class' => 'four', 'min' => 1));
$form->addElement('checkbox', 'add_to_my_reports', ts('Add to My Reports?'), NULL);
$form->addElement('checkbox', 'is_reserved', ts('Reserved Report?'));
if (!CRM_Core_Permission::check('administer reserved reports')) {
$form->freeze('is_reserved');
}
$config = CRM_Core_Config::singleton();
if ($config->userFramework != 'Joomla' || $config->userFramework != 'WordPress') {
$form->addElement('select', 'permission', ts('Permission'), array('0' => ts('Everyone (includes anonymous)')) + CRM_Core_Permission::basicPermissions());
// prepare user_roles to save as names not as ids
if (function_exists('user_roles')) {
$user_roles_array = user_roles();
foreach ($user_roles_array as $key => $value) {
$user_roles[$value] = $value;
}
$grouprole =& $form->addElement('advmultiselect', 'grouprole', ts('ACL Group/Role'), $user_roles, array('size' => 5, 'style' => 'width:240px', 'class' => 'advmultiselect'));
$grouprole->setButtonAttributes('add', array('value' => ts('Add >>')));
$grouprole->setButtonAttributes('remove', array('value' => ts('<< Remove')));
}
}
// navigation field
$parentMenu = CRM_Core_BAO_Navigation::getNavigationList();
$form->add('select', 'parent_id', ts('Parent Menu'), array('' => ts('- select -')) + $parentMenu);
// For now we only providing drilldown for one primary detail report only. In future this could be multiple reports
foreach ($form->_drilldownReport as $reportUrl => $drillLabel) {
$instanceList = CRM_Report_Utils_Report::getInstanceList($reportUrl);
if (count($instanceList) > 1) {
$form->add('select', 'drilldown_id', $drillLabel, array('' => ts('- select -')) + $instanceList);
}
break;
}
$form->addButtons(array(array('type' => 'submit', 'name' => ts('Save Report'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
$form->addFormRule(array('CRM_Report_Form_Instance', 'formRule'), $form);
}
示例2: buildProfile
/**
* Add profile field to a form.
*
* @param CRM_Core_Form $form
* @param array $field
* Properties.
* @param int $mode
* Profile mode.
* @param int $contactId
* @param bool $online
* @param string $usedFor
* For building up prefixed fieldname for special cases (e.g. onBehalf, Honor).
* @param int $rowNumber
* @param string $prefix
*
* @return null
*/
public static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $usedFor = NULL, $rowNumber = NULL, $prefix = '')
{
$defaultValues = array();
$fieldName = $field['name'];
$title = $field['title'];
$attributes = $field['attributes'];
$rule = $field['rule'];
$view = $field['is_view'];
$required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required'];
$search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE;
$isShared = CRM_Utils_Array::value('is_shared', $field, 0);
// do not display view fields in drupal registration form
// CRM-4632
if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) {
return NULL;
}
if ($usedFor == 'onbehalf') {
$name = "onbehalf[{$fieldName}]";
} elseif ($usedFor == 'honor') {
$name = "honor[{$fieldName}]";
} elseif ($contactId && !$online) {
$name = "field[{$contactId}][{$fieldName}]";
} elseif ($rowNumber) {
$name = "field[{$rowNumber}][{$fieldName}]";
} elseif (!empty($prefix)) {
$name = $prefix . "[{$fieldName}]";
} else {
$name = $fieldName;
}
$selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE);
if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) {
$deleteExtra = json_encode(ts('Are you sure you want to delete contact image.'));
$deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "' . htmlspecialchars("if (confirm({$deleteExtra})) this.href+='&confirmed=1'; else return false;") . '"'));
$deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')), ts('more'), FALSE, 'contact.profileimage.delete', 'Contact', $form->get('id'));
$form->assign('deleteURL', $deleteURL);
}
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
if (substr($fieldName, 0, 14) === 'state_province') {
$form->addChainSelect($name, array('label' => $title, 'required' => $required));
$config = CRM_Core_Config::singleton();
if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactStateProvince) {
$defaultValues[$name] = $config->defaultContactStateProvince;
$form->setDefaults($defaultValues);
}
} elseif (substr($fieldName, 0, 7) === 'country') {
$form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes);
$config = CRM_Core_Config::singleton();
if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) {
$defaultValues[$name] = $config->defaultContactCountry;
$form->setDefaults($defaultValues);
}
} elseif (substr($fieldName, 0, 6) === 'county') {
if ($addressOptions['county']) {
$form->addChainSelect($name, array('label' => $title, 'required' => $required));
}
} elseif (substr($fieldName, 0, 9) === 'image_URL') {
$form->add('file', $name, $title, $attributes, $required);
$form->addUploadElement($name);
} elseif (substr($fieldName, 0, 2) === 'im') {
$form->add('text', $name, $title, $attributes, $required);
if (!$contactId) {
if ($usedFor) {
if (substr($name, -1) == ']') {
$providerName = substr($name, 0, -1) . '-provider_id]';
}
$form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
} else {
$form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required);
}
if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) {
$form->freeze($name . '-provider_id');
}
}
} elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') {
$form->addDate($name, $title, $required, array('formatType' => 'birth'));
} elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) {
$form->addDate($name, $title, $required, array('formatType' => 'activityDate'));
} elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') {
list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
$sel =& $form->addElement('hierselect', $name, $title);
$select = array('' => ts('- select -'));
if (count($orgInfo) == 1 && $field['is_required']) {
// we only have one org - so we should default to it. Not sure about defaulting to first type
//.........这里部分代码省略.........
示例3: addQuickFormElement
//.........这里部分代码省略.........
$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);
}
}