You are here

public function FlexiformElementUserMail::form in Flexiform 7

Return the form element for this FlexiformElement.

Overrides FlexiformElement::form

File

includes/element/user_mail.element.inc, line 15
Contains class for the User mail element.

Class

FlexiformElementUserMail
Class to add the User mail field to a form.

Code

public function form($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
  $parents = $form['#parents'];
  $parents[] = 'mail';

  // Work out the default value.
  $default = '';
  if (!empty($this->settings['default_value']['default_value'])) {
    $default = $this->settings['default_value']['default_value'];
  }
  if (!empty($this->settings['default_value']['use_tokens'])) {
    $default = $this
      ->replaceCtoolsSubstitutions($default, $form['#flexiform_entities']);
  }
  $form[$this->element_namespace] = array(
    '#type' => 'textfield',
    '#parents' => $parents,
    '#title' => $this
      ->label(),
    '#required' => FALSE,
    '#default_value' => !empty($entity->mail) ? $entity->mail : $default,
    '#maxlength' => 255,
  );
  $form = parent::form($form, $form_state, $entity);
  return $form;
}