You are here

public static function CardExpiration::preRenderCardExpiration in Creditfield Form Element 8

Adds form-specific attributes to a 'creditfield_expiration' #type element.

Supports HTML5 types of 'date', 'datetime', 'datetime-local', and 'time'. Falls back to a plain textfield. Used as a sub-element by the datetime element type.

Parameters

array $element: An associative array containing the properties of the element. Properties used: #title, #value, #options, #description, #required, #attributes, #id, #name, #type, #min, #max, #step, #value, #size.

Note: The input "name" attribute needs to be sanitized before output, which is currently done by initializing Drupal\Core\Template\Attribute with all the attributes.

Return value

array The $element with prepared variables ready for #theme 'input__date'.

File

src/Element/CardExpiration.php, line 73

Class

CardExpiration
Provides a one-line credit card number field form element.

Namespace

Drupal\creditfield\Element

Code

public static function preRenderCardExpiration($element) {
  $element['#attributes']['type'] = 'month';
  Element::setAttributes($element, [
    'id',
    'name',
    'type',
    'min',
    'max',
    'step',
    'value',
    'size',
  ]);
  static::setAttributes($element, [
    'form-' . $element['#attributes']['type'],
  ]);
  return $element;
}