You are here

public function PageJsonForm::buildForm in Structured Data (JSON+LD Rich Snippets) 8

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 FormInterface::buildForm

File

src/Form/PageJsonForm.php, line 27

Class

PageJsonForm
Class PageJsonForm.

Namespace

Drupal\structured_data\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $entity = $this
    ->getEntity();
  $form['route_name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Route Name'),
    '#required' => TRUE,
    '#default_value' => $entity->route_name,
  ];
  $form['url'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Url'),
    '#required' => FALSE,
    '#default_value' => $entity->url,
  ];
  $form['bundle'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Bundle'),
    '#required' => FALSE,
    '#default_value' => $entity->bundle === Helper::EMPTY_BUNDLE ? '' : $entity->bundle,
  ];
  $form['entity_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Entity Id'),
    '#required' => FALSE,
    '#default_value' => $entity->entity_id == '0' ? '' : $entity->entity_id,
  ];
  $form['json'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Json'),
    '#required' => FALSE,
    '#default_value' => $entity->json,
  ];
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
    '#button_type' => 'primary',
  ];
  return $form;
}