You are here

function _webform_render_countdown in Webform Countdown 7.2

Same name and namespace in other branches
  1. 7 webform_countdown.module \_webform_render_countdown()

Implements _webform_render_component().

File

./webform_countdown.module, line 168
Webform countdown code module.

Code

function _webform_render_countdown($component, $value = NULL, $filter = TRUE) {
  $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
  $element = array(
    '#type' => 'textarea',
    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
    '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
    '#default_value' => $filter ? webform_replace_tokens($component['value'], $node, NULL, NULL, FALSE) : $component['value'],
    '#required' => $component['required'],
    '#weight' => $component['weight'],
    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
    '#rows' => !empty($component['extra']['rows']) ? $component['extra']['rows'] : 5,
    '#cols' => !empty($component['extra']['cols']) ? $component['extra']['cols'] : 60,
    '#attributes' => $component['extra']['attributes'],
    '#resizable' => (bool) $component['extra']['resizable'],
    // MUST be FALSE to disable.
    '#theme_wrappers' => array(
      'webform_element',
    ),
    '#translatable' => array(
      'title',
      'description',
    ),
    '#element_validate' => array(
      'webform_countdown_validate',
    ),
    '#attached' => array(
      'js' => _webform_countdown_add_counter($component['form_key'], $component['extra']['max'], $component['extra']['type'], $component['extra']['message']),
    ),
  );
  if ($component['required']) {
    $element['#attributes']['required'] = 'required';
  }
  if ($component['extra']['placeholder']) {
    $element['#attributes']['placeholder'] = $component['extra']['placeholder'];
  }
  if ($component['extra']['disabled']) {
    if ($filter) {
      $element['#attributes']['readonly'] = 'readonly';
    }
    else {
      $element['#disabled'] = TRUE;
    }
  }
  if (isset($value[0])) {
    $element['#default_value'] = $value[0];
  }
  return $element;
}