You are here

class UcAddressesAddressNameFieldHandler in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 handlers/uc_addresses.handlers.inc \UcAddressesAddressNameFieldHandler

Class for the address name field.

Hierarchy

Expanded class hierarchy of UcAddressesAddressNameFieldHandler

2 string references to 'UcAddressesAddressNameFieldHandler'
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 57
Field handlers for Ubercart Addresses address fields:

View source
class UcAddressesAddressNameFieldHandler extends UcAddressesFieldHandler {

  /**
   * Implements UcAddressesFieldHandler::init().
   *
   * @throws UcAddressesIncompatibleHandlerException
   *   In case the given address instance is not an instance of
   *   UcAddressesAddress.
   */
  protected function init() {
    $address = $this
      ->getAddress();
    if (!$address instanceof UcAddressesAddress) {
      throw new UcAddressesIncompatibleHandlerException(t('The handler %handler needs an UcAddressesAddress instance to function.', array(
        '%handler' => get_class($this),
      )));
    }
  }

  /**
   * 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;
    return array(
      $fieldName => array(
        '#type' => 'textfield',
        '#title' => t('Save as'),
        '#description' => t('Enter a name for this address (e.g. Home or Work)'),
        '#default_value' => $default,
        '#required' => $this
          ->isFieldRequired(),
        '#maxlength' => 20,
        '#size' => 32,
      ),
    );
  }

  /**
   * Implements UcAddressesFieldHandler::isFieldEnabled().
   */
  public function isFieldEnabled() {
    return variable_get('uc_addresses_use_address_name', TRUE);
  }

  /**
   * Implements UcAddressesFieldHandler::isFieldRequired().
   */
  public function isFieldRequired() {
    return FALSE;
  }

  /**
   * Implements UcAddressesFieldHandler::validateValue().
   *
   * Checks if the given name is unique.
   */
  public function validateValue(&$value) {
    $fieldName = $this
      ->getFieldName();
    if ($value) {
      if (!$this
        ->getAddress()
        ->setName($value)) {
        form_set_error($fieldName, t('You already have an address named %name in your address book.', array(
          '%name' => $value,
        )));
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UcAddressesAddressNameFieldHandler::getFormField public function Implements UcAddressesFieldHandler::getFormField(). Overrides UcAddressesFieldHandler::getFormField
UcAddressesAddressNameFieldHandler::init protected function Implements UcAddressesFieldHandler::init(). Overrides UcAddressesFieldHandler::init
UcAddressesAddressNameFieldHandler::isFieldEnabled public function Implements UcAddressesFieldHandler::isFieldEnabled(). Overrides UcAddressesFieldHandler::isFieldEnabled
UcAddressesAddressNameFieldHandler::isFieldRequired public function Implements UcAddressesFieldHandler::isFieldRequired(). Overrides UcAddressesFieldHandler::isFieldRequired
UcAddressesAddressNameFieldHandler::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::getOutputFormats public function Returns an array of possible output formats the handler supports. 3
UcAddressesFieldHandler::getProperty final public function Returns a property from the field definition.
UcAddressesFieldHandler::outputValue public function Output a field's value. 3
UcAddressesFieldHandler::setValue public function Sets value in the address object.
UcAddressesFieldHandler::__construct final public function UcAddressesFormField object constructor.