You are here

public function FlexiformElementNodeAuthor::formValidate in Flexiform 7

Validate the form element.

Overrides FlexiformElement::formValidate

File

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

Class

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

Code

public function formValidate($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
  $author = $this
    ->formExtractValues($form, $form_state, $entity);
  $entity->name = $author;

  // Validate the "authored by" field.
  if (!empty($entity->name) && !($account = user_load_by_name($entity->name))) {

    // The use of empty() is mandatory in the context of usernames
    // as the empty string denotes the anonymous user. In case we
    // are dealing with an anonymous user we set the user ID to 0.
    form_set_error('name', t('The username %name does not exist.', array(
      '%name' => $entity->name,
    )));
  }
}