You are here

public function ViewTemplateForm::buildForm in Views Templates 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/ViewTemplateForm.php, line 57

Class

ViewTemplateForm
Form controller for the view template entity add forms.

Namespace

Drupal\views_templates

Code

public function buildForm(array $form, FormStateInterface $form_state, $view_template = NULL) {
  $builder = $this
    ->createBuilder($view_template);
  $form['#title'] = $this
    ->t('Duplicate of @label', [
    '@label' => $builder
      ->getAdminLabel(),
  ]);
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('View name'),
    '#required' => TRUE,
    '#size' => 32,
    '#maxlength' => 255,
    '#default_value' => $builder
      ->getAdminLabel(),
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#maxlength' => 128,
    '#machine_name' => [
      'exists' => '\\Drupal\\views\\Views::getView',
      'source' => [
        'label',
      ],
    ],
    '#default_value' => '',
    '#description' => $this
      ->t('A unique machine-readable name for this View. It must only contain lowercase letters, numbers, and underscores.'),
  ];
  $form['description'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Description'),
    '#default_value' => $builder
      ->getDescription(),
  ];
  $form['builder_id'] = [
    '#type' => 'value',
    '#value' => $builder
      ->getPluginId(),
  ];
  $form += $builder
    ->buildConfigurationForm($form, $form_state);
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Create View'),
  ];
  return $form;
}