You are here

class UcAddressesDateFieldHandler in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 handlers/uc_addresses.handlers.inc \UcAddressesDateFieldHandler

Class for the created/modified field.

Hierarchy

Expanded class hierarchy of UcAddressesDateFieldHandler

2 string references to 'UcAddressesDateFieldHandler'
uc_addresses_uc_addresses_fields in ./uc_addresses.uc_addresses_fields.inc
Implements hook_uc_addresses_fields().
uc_addresses_uc_addresses_field_handlers in ./uc_addresses.uc_addresses_fields.inc
Implements 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
  // -----------------------------------------------------------------------------

  /**
   * Overrides UcAddressesFieldHandler::getTokenInfo().
   *
   * Specifies that tokens of this field are of type 'date'.
   */
  public function getTokenInfo() {
    $fieldname = $this
      ->getFieldName();
    $tokens = parent::getTokenInfo();
    $tokens[$fieldname] = array(
      'name' => $this
        ->getFieldTitle(),
      'description' => $this
        ->getProperty('description'),
      'type' => 'date',
    );
    return $tokens;
  }

  /**
   * 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 = '') {
    $values =& drupal_static('UcAddressesDateFieldHandler::outputValue', array());
    if ($value === '') {
      $value = $this
        ->getAddress()
        ->getField($this
        ->getFieldName());
    }
    if (isset($values[$value][$format])) {
      return $values[$value][$format];
    }
    if ($format) {
      $token = token_generate('date', array(
        $format => $format,
      ), array(
        'date' => $value,
      ));
      if (isset($token[$format])) {
        $values[$value][$format] = $token[$format];
      }
    }
    else {
      $values[$value][$format] = format_date($value);
    }
    if (isset($values[$value][$format])) {
      return $values[$value][$format];
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UcAddressesDateFieldHandler::getFormField public function Implements UcAddressesFieldHandler::getFormField(). Overrides UcAddressesFieldHandler::getFormField
UcAddressesDateFieldHandler::getTokenInfo public function Overrides UcAddressesFieldHandler::getTokenInfo(). Overrides UcAddressesFieldHandler::getTokenInfo
UcAddressesDateFieldHandler::isFieldEnabled public function Implements UcAddressesFieldHandler::isFieldEnabled(). Overrides UcAddressesFieldHandler::isFieldEnabled
UcAddressesDateFieldHandler::isFieldRequired public function Implements UcAddressesFieldHandler::isFieldRequired(). Overrides UcAddressesFieldHandler::isFieldRequired
UcAddressesDateFieldHandler::outputValue public function Overrides UcAddressesFieldHandler::outputValue(). Overrides UcAddressesFieldHandler::outputValue
UcAddressesDateFieldHandler::validateValue public function Implements UcAddressesFieldHandler::validateValue(). Overrides UcAddressesFieldHandler::validateValue
UcAddressesFieldHandler::$address private property Address object.
UcAddressesFieldHandler::$context private property The context in which this field is used.
UcAddressesFieldHandler::$definition private property The declared field definition.
UcAddressesFieldHandler::$name private property Name of this field.
UcAddressesFieldHandler::checkContext public function Checks if the field passes the context. 1
UcAddressesFieldHandler::getAddress final public function Returns the address attached to this field.
UcAddressesFieldHandler::getContext final public function Returns the context in which this field is used.
UcAddressesFieldHandler::getDefaultValue public function Returns a default value for this field. 3
UcAddressesFieldHandler::getFieldName final public function Returns the field name.
UcAddressesFieldHandler::getFieldTitle public function Returns the title to use when displaying a field. 1
UcAddressesFieldHandler::getMappingTargets public function Returns supported mapping targets for Feeds. 2
UcAddressesFieldHandler::getOutputFormats public function Returns an array of possible output formats the handler supports. 2
UcAddressesFieldHandler::getProperty final public function Returns a property from the field definition.
UcAddressesFieldHandler::init protected function Can be used by subclasses to do some initialization upon construction of the object. 2
UcAddressesFieldHandler::mapValue public function Set a fields value based on the output format. 2
UcAddressesFieldHandler::setValue public function Sets value in the address object.
UcAddressesFieldHandler::__construct final public function UcAddressesFormField object constructor.