function _uc_extra_fields_pane_address_fields_uc_store_address_fields_alter in Extra Fields Checkout Pane 6.2
_uc_extra_fields_pane_address_fields_uc_store_address_fields_alter() Adds extra address fields to form which can be defined at /admin/store/settings/addressfields/add
_state @access private
Parameters
array $form:
See also
_uc_extra_fields_pane_address_fields_uc_store_address_fields_submit()
1 call to _uc_extra_fields_pane_address_fields_uc_store_address_fields_alter()
- uc_extra_fields_pane_form_alter in ./
uc_extra_fields_pane.module - Implementation of hook_form_alter().
File
- includes/
addressfields.inc, line 24 - These functions adds extra address fields to forms
Code
function _uc_extra_fields_pane_address_fields_uc_store_address_fields_alter(&$form, $form_state) {
if (isset($form['uc_address_fields'])) {
// We're dealing with an Ubercart version dated July 18, 2012 or later.
// Some fields are structured differently.
$uc_version_20120718 = TRUE;
}
else {
$uc_version_20120718 = FALSE;
}
try {
$fields = UCXF_FieldList::getFieldsFromPane(array(
'extra_delivery',
'extra_billing',
));
// Similar to uc_store_address_fields_form() from uc_store.module
foreach ($fields as $fieldname => $field) {
if ($uc_version_20120718) {
// The "enabled" setting is inside "$form['uc_address_fields']'.
$form['fields'][$fieldname]['#summary callback'] = 'summarize_form';
$form['uc_address_fields'][$fieldname] = array(
'#type' => 'checkbox',
'#summary callback' => 'summarize_checkbox',
'#summary arguments' => array(
t('@field is enabled.', array(
'@field' => $field->label,
)),
t('@field is disabled.', array(
'@field' => $field->label,
)),
),
'#default_value' => $field->enabled ? TRUE : FALSE,
);
// The "required" setting is inside "$form['uc_address_fields_required']'.
$form['uc_address_fields_required'][$fieldname] = array(
'#type' => 'checkbox',
'#default_value' => $field->required ? TRUE : FALSE,
);
// Title field.
$form['fields'][$fieldname]['uc_field_' . $fieldname] = array(
'#value' => $field
->output('label'),
);
}
else {
// This is valid when using Ubercart 6.x-2.3 through Ubercart 6.x-2.9.
$form['fields'][$fieldname]['#summary callback'] = 'summarize_form';
$form['fields'][$fieldname]['enabled'] = array(
'#type' => 'checkbox',
'#summary callback' => 'summarize_checkbox',
'#summary arguments' => array(
t('@field is enabled.', array(
'@field' => $field->label,
)),
t('@field is disabled.', array(
'@field' => $field->label,
)),
),
'#default_value' => $field->enabled ? TRUE : FALSE,
);
$form['fields'][$fieldname]['required'] = array(
'#type' => 'checkbox',
'#default_value' => $field->required ? TRUE : FALSE,
);
$form['fields'][$fieldname]['title'] = array(
'#value' => $field
->output('label'),
);
// Add id of field.
$form['fields'][$fieldname]['field_id'] = array(
'#type' => 'value',
'#value' => $field->field_id,
);
}
// Add field machine name.
$form['fields'][$fieldname]['default'] = array(
'#value' => $field->db_name,
);
// Add action links.
$links = array();
if (uc_extra_fields_pane_access($field, 'edit')) {
$links['edit'] = l(t('edit'), 'admin/store/settings/addressfields/' . $field->field_id . '/edit');
}
if (uc_extra_fields_pane_access($field, 'delete')) {
$links['delete'] = l(t('delete'), 'admin/store/settings/addressfields/' . $field->field_id . '/delete');
}
if (count($links) > 0) {
$form['fields'][$fieldname]['action'] = array(
'#value' => implode(' | ', $links),
);
}
}
// Add link to add an address field.
// This field will be shown above the table as is usual in
// the 7.x-1.x version of Extra Fields Pane.
$form['add_field'] = array(
'#type' => 'markup',
'#value' => l('+ ' . t('Add an address field'), 'admin/store/settings/addressfields/add', array(
'attributes' => array(
'class' => 'ucxf-add-field-link ucxf-add-field-link-1',
),
)) . '<br /><br />',
);
// Add a second link to add an address field.
// This field will be shown below the table as was usual in
// 6.x-2.0-beta2 and older versions of Extra Fields Pane.
$form['add_field2'] = array(
'#type' => 'markup',
'#value' => l('+ ' . t('Add an address field'), 'admin/store/settings/addressfields/add', array(
'attributes' => array(
'class' => 'ucxf-add-field-link ucxf-add-field-link-2',
),
)) . '<br /><br />',
);
// Add submit function so 'enabled' and 'required' can be saved
$form['#submit'][] = 'uc_extra_fields_pane_address_fields_uc_store_address_fields_submit';
} catch (UCXF_Exception $e) {
$e
->printMessage();
$e
->logError();
}
}