You are here

public function EditForm::buildForm in Linkit 8.4

Same name in this branch
  1. 8.4 src/Form/Attribute/EditForm.php \Drupal\linkit\Form\Attribute\EditForm::buildForm()
  2. 8.4 src/Form/Matcher/EditForm.php \Drupal\linkit\Form\Matcher\EditForm::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 FormInterface::buildForm

File

src/Form/Attribute/EditForm.php, line 45
Contains \Drupal\linkit\Form\Attribute\EditForm.

Class

EditForm
Provides an edit form for attributes.

Namespace

Drupal\linkit\Form\Attribute

Code

public function buildForm(array $form, FormStateInterface $form_state, ProfileInterface $linkit_profile = NULL, $plugin_instance_id = NULL) {
  $this->linkitProfile = $linkit_profile;
  $this->linkitAttribute = $this->linkitProfile
    ->getAttribute($plugin_instance_id);
  $form['data'] = [
    '#tree' => true,
  ];
  $form['data'] += $this->linkitAttribute
    ->buildConfigurationForm($form, $form_state);
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Save changes'),
    '#submit' => array(
      '::submitForm',
    ),
    '#button_type' => 'primary',
  );
  $form['actions']['delete'] = array(
    '#type' => 'link',
    '#title' => $this
      ->t('Delete'),
    '#url' => Url::fromRoute('linkit.attribute.delete', [
      'linkit_profile' => $this->linkitProfile
        ->id(),
      'plugin_instance_id' => $this->linkitAttribute
        ->getPluginId(),
    ]),
    '#attributes' => [
      'class' => [
        'button',
        'button--danger',
      ],
    ],
  );
  return $form;
}