You are here

public function SimplemetaEntityForm::buildForm in Simple Meta 8

Same name and namespace in other branches
  1. 8.2 src/Form/SimplemetaEntityForm.php \Drupal\simplemeta\Form\SimplemetaEntityForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EntityForm::buildForm

File

src/Form/SimplemetaEntityForm.php, line 18

Class

SimplemetaEntityForm
Form controller for SimpleMeta edit forms.

Namespace

Drupal\simplemeta\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  /* @var $entity \Drupal\simplemeta\Entity\SimplemetaEntity */
  $form = parent::buildForm($form, $form_state);
  $entity = $this->entity;
  $data = $entity
    ->isNew() ? [] : $entity
    ->get('data')
    ->get(0)
    ->getValue();
  $form['data'] = array(
    '#tree' => TRUE,
  );

  // Meta title.
  $form['data']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#maxlength' => 255,
    '#default_value' => isset($data['title']) ? $data['title'] : '',
  );

  // Meta description.
  $form['data']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#resizable' => FALSE,
    '#default_value' => isset($data['description']) ? $data['description'] : '',
  );
  $form['data']['keywords'] = array(
    '#type' => 'textfield',
    '#title' => t('Keywords'),
    '#description' => t('Comma-separated list of keywords.'),
    '#maxlength' => 255,
    '#default_value' => isset($data['keywords']) ? $data['keywords'] : '',
  );
  return $form;
}