<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
self::$_dataToHTML = CRM_Core_BAO_CustomField::dataToHtml();
}
- //custom group id
- $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
+ //custom field id
+ $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
+
+ $this->_values = array();
+ //get the values form db if update.
+ if ($this->_id) {
+ $params = array('id' => $this->_id);
+ CRM_Core_BAO_CustomField::retrieve($params, $this->_values);
+ // note_length is an alias for the text_length field
+ $this->_values['note_length'] = CRM_Utils_Array::value('text_length', $this->_values);
+ // custom group id
+ $this->_gid = $this->_values['custom_group_id'];
+ }
+ else {
+ // custom group id
+ $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
+ }
if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) {
CRM_Core_Error::fatal("You cannot add or edit fields in a reserved custom field-set.");
$session->pushUserContext($url);
}
- //custom field id
- $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
-
- //get the values form db if update.
- $this->_values = array();
- if ($this->_id) {
- $params = array('id' => $this->_id);
- CRM_Core_BAO_CustomField::retrieve($params, $this->_values);
- // note_length is an alias for the text_length field
- $this->_values['note_length'] = CRM_Utils_Array::value('text_length', $this->_values);
- }
-
if (self::$_dataToLabels == NULL) {
self::$_dataToLabels = array(
array('Text' => ts('Text'), 'Select' => ts('Select'),
$defaults['default_value'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Country', $countryId);
}
- if ($defaults['data_type'] == 'ContactReference' && CRM_Utils_Array::value('filter', $defaults)) {
+ if ($defaults['data_type'] == 'ContactReference' && !empty($defaults['filter'])) {
$contactRefFilter = 'Advance';
if (strpos($defaults['filter'], 'action=lookup') !== FALSE &&
strpos($defaults['filter'], 'group=') !== FALSE
$defaults['filter_selected'] = $contactRefFilter;
}
- if (CRM_Utils_Array::value('data_type', $defaults)) {
+ if (!empty($defaults['data_type'])) {
$defaultDataType = array_search($defaults['data_type'],
self::$_dataTypeKeys
);
$defaults['is_view'] = 0;
}
- if (CRM_Utils_Array::value('html_type', $defaults)) {
+ if (!empty($defaults['html_type'])) {
$dontShowLink = substr($defaults['html_type'], -14) == 'State/Province' || substr($defaults['html_type'], -7) == 'Country' ? 1 : 0;
}
if (isset($dontShowLink)) {
$this->assign('dontShowLink', $dontShowLink);
}
+ if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_multiple', 'id')) {
+ $defaults['in_selector'] = 1;
+ }
+
return $defaults;
}
public function buildQuickForm() {
if ($this->_gid) {
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'title');
- CRM_Utils_System::setTitle($this->_title . ' - ' . ts('Custom Fields'));
+ CRM_Utils_System::setTitle($this->_title . ' - ' . ($this->_id ? ts('Edit Field') : ts('Add Field')));
+ $this->assign('gid', $this->_gid);
}
// lets trim all the whitespace
' '
);
$sel->setOptions(array($dt, $it));
+
+ if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_multiple')) {
+ $this->add('checkbox', 'in_selector', ts('Display in Table?'));
+ }
+
if ($this->_action == CRM_Core_Action::UPDATE) {
$this->freeze('data_type');
}
break;
case 'ContactReference':
- if ($fields['filter_selected'] == 'Advance' &&
- CRM_Utils_Array::value('filter', $fields)
- ) {
+ if ($fields['filter_selected'] == 'Advance' && !empty($fields['filter'])) {
if (strpos($fields['filter'], 'entity=') !== FALSE) {
$errors['filter'] = ts("Please do not include entity parameter (entity is always 'contact')");
}
}
$optionFields = array('Select', 'Multi-Select', 'CheckBox', 'Radio', 'AdvMulti-Select');
- if ($fields['option_type'] == 1) {
+ if (isset($fields['option_type']) && $fields['option_type'] == 1) {
//capture duplicate Custom option values
if (!empty($fields['option_value'])) {
$countValue = count($fields['option_value']);
}
// we can not set require and view at the same time.
- if (CRM_Utils_Array::value('is_required', $fields) &&
- CRM_Utils_Array::value('is_view', $fields)
- ) {
+ if (!empty($fields['is_required']) && !empty($fields['is_view'])) {
$errors['is_view'] = ts('Can not set this field Required and View Only at the same time.');
}
//fix for 'is_search_range' field.
if (in_array($dataTypeKey, array(
1, 2, 3, 5))) {
- if (!CRM_Utils_Array::value('is_searchable', $params)) {
+ if (empty($params['is_searchable'])) {
$params['is_search_range'] = 0;
}
}
}
$filter = 'null';
- if ($dataTypeKey == 11 && CRM_Utils_Array::value('filter_selected', $params)) {
+ if ($dataTypeKey == 11 && !empty($params['filter_selected'])) {
if ($params['filter_selected'] == 'Advance' && trim(CRM_Utils_Array::value('filter', $params))) {
$filter = trim($params['filter']);
}
- elseif ($params['filter_selected'] == 'Group' && CRM_Utils_Array::value('group_id', $params)) {
+ elseif ($params['filter_selected'] == 'Group' && !empty($params['group_id'])) {
$filter = 'action=lookup&group=' . implode(',', $params['group_id']);
}
}
$customField = CRM_Core_BAO_CustomField::create($params);
+ $this->_id = $customField->id;
// reset the cache
CRM_Core_BAO_Cache::deleteGroup('contact fields');
- CRM_Core_Session::setStatus(ts('Your custom field \'%1\' has been saved.',
- array(1 => $customField->label)
- ), ts('Saved'), 'success');
+ $msg = '<p>' . ts("Custom field '%1' has been saved.", array(1 => $customField->label)) . '</p>';
$buttonName = $this->controller->getButtonName();
$session = CRM_Core_Session::singleton();
if ($buttonName == $this->getButtonName('next', 'new')) {
- CRM_Core_Session::setStatus(ts(' You can add another custom field.'), '', 'info');
+ $msg += '<p>' . ts("Ready to add another.") . '</p>';
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/add',
'reset=1&action=add&gid=' . $this->_gid
));
'reset=1&action=browse&gid=' . $this->_gid
));
}
+ $session->setStatus($msg, ts('Saved'), 'success');
+
+ // Add data when in ajax contect
+ $this->ajaxResponse['customField'] = $customField->toArray();
}
}