You are here

public function FlexiformElementNodeAuthor::form in Flexiform 7

Return the form element for this FlexiformElement.

Overrides FlexiformElement::form

File

includes/element/node_author.element.inc, line 15
Contains class for the Node author element.

Class

FlexiformElementNodeAuthor
Class to add the node author field to a form.

Code

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

  // If the node has the UID set then we load that user as the default,
  // otherwise use the global user.
  if (isset($entity->uid)) {
    $account = user_load($entity->uid);
  }
  else {
    if (!empty($this->settings['default_value']['use_current'])) {
      $account = $user;
    }
  }

  // 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(),
    '#autocomplete_path' => 'user/autocomplete',
    '#default_value' => !empty($account->name) ? $account->name : $default,
    '#maxlength' => 60,
    '#description' => t('Leave blank for %anonymous.', array(
      '%anonymous' => variable_get('anonymous', t('Anonymous')),
    )),
  );
  $form = parent::form($form, $form_state, $entity);
  return $form;
}