class UcAddressesDateFieldHandler in Ubercart Addresses 6.2
Same name and namespace in other branches
- 7 handlers/uc_addresses.handlers.inc \UcAddressesDateFieldHandler
Class for the created/modified field.
Hierarchy
- class \UcAddressesFieldHandler
- class \UcAddressesDateFieldHandler
Expanded class hierarchy of UcAddressesDateFieldHandler
2 string references to 'UcAddressesDateFieldHandler'
- uc_addresses_uc_addresses_fields in ./
uc_addresses.uc_addresses_fields.inc - Implementation of hook_uc_addresses_fields().
- uc_addresses_uc_addresses_field_handlers in ./
uc_addresses.uc_addresses_fields.inc - Implementation of hook_uc_addresses_field_handlers().
File
- handlers/
uc_addresses.handlers.inc, line 215 - Field handlers for Ubercart Addresses address fields:
View source
class UcAddressesDateFieldHandler extends UcAddressesFieldHandler {
/**
* Implements UcAddressesFieldHandler::getFormField().
*/
public function getFormField($form, $form_values) {
$fieldName = $this
->getFieldName();
$fieldValue = $this
->getAddress()
->getField($fieldName);
$default = isset($form_values[$fieldName]) ? $form_values[$fieldName] : $fieldValue;
if (is_numeric($default)) {
$default = array(
'hour' => date('H', $default),
'minute' => date('i', $default),
'second' => date('s', $default),
'month' => date('n', $default),
'day' => date('j', $default),
'year' => date('Y', $default),
);
}
return array(
$fieldName => array(
'#type' => 'date',
'#title' => $this
->getFieldTitle(),
'#default_value' => $default,
'#required' => $this
->isFieldRequired(),
),
);
}
/**
* Implements UcAddressesFieldHandler::isFieldEnabled().
*/
public function isFieldEnabled() {
return TRUE;
}
/**
* Implements UcAddressesFieldHandler::isFieldRequired().
*/
public function isFieldRequired() {
return FALSE;
}
// -----------------------------------------------------------------------------
// VALIDATE
// -----------------------------------------------------------------------------
/**
* Implements UcAddressesFieldHandler::validateValue().
*
* Makes sure the value is converted to a timestamp.
*/
public function validateValue(&$value) {
$value = mktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
}
// -----------------------------------------------------------------------------
// OUTPUT
// -----------------------------------------------------------------------------
/**
* Implements UcAddressesFieldHandler::getOutputFormats().
*
* Returns an array of output formats for the date field.
*/
public function getOutputFormats() {
return token_get_date_token_info($this
->getProperty('description') . ',', $this
->getFieldName() . '-');
}
/**
* Overrides UcAddressesFieldHandler::outputValue().
*
* If a format is specified, the value will be formatted using that (date) format.
* If no format is specified, the value will be formatted using the site default
* date format.
*/
public function outputValue($value = '', $format = '') {
static $values = array();
if ($value === '') {
$value = $this
->getAddress()
->getField($this
->getFieldName());
}
if (isset($values[$value][$format])) {
return $values[$value][$format];
}
$values[$value] = token_get_date_token_values($value, $this
->getFieldName() . '-');
if (isset($values[$value][$format])) {
return $values[$value][$format];
}
}
}