You are here

public function GdprFieldSettingsForm::buildForm in General Data Protection Regulation 8

Same name and namespace in other branches
  1. 8.2 modules/gdpr_fields/src/Form/GdprFieldSettingsForm.php \Drupal\gdpr_fields\Form\GdprFieldSettingsForm::buildForm()
  2. 3.0.x modules/gdpr_fields/src/Form/GdprFieldSettingsForm.php \Drupal\gdpr_fields\Form\GdprFieldSettingsForm::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.

string $entity_type: The entity type.

string $bundle_name: The entity bundle.

string $field_name: The field name.

Return value

array The form structure.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

Overrides FormInterface::buildForm

File

modules/gdpr_fields/src/Form/GdprFieldSettingsForm.php, line 169

Class

GdprFieldSettingsForm
GDPR Field settings.

Namespace

Drupal\gdpr_fields\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $entity_type = NULL, $bundle_name = NULL, $field_name = NULL) {
  if (empty($entity_type) || empty($bundle_name) || empty($field_name)) {
    $this
      ->messenger()
      ->addWarning('Could not load field.');
    return [];
  }
  $field_defs = $this->entityFieldManager
    ->getFieldDefinitions($entity_type, $bundle_name);
  if (!array_key_exists($field_name, $field_defs)) {
    $this
      ->messenger()
      ->addWarning("The field {$field_name} does not exist.");
    return [];
  }
  $field_def = $field_defs[$field_name];
  $form['#title'] = 'GDPR Settings for ' . $field_def
    ->getLabel();
  static::buildFormFields($form, $entity_type, $bundle_name, $field_name);
  $form['entity_type'] = [
    '#type' => 'hidden',
    '#default_value' => $entity_type,
  ];
  $form['bundle'] = [
    '#type' => 'hidden',
    '#default_value' => $bundle_name,
  ];
  $form['field_name'] = [
    '#type' => 'hidden',
    '#default_value' => $field_name,
  ];
  $form['actions'] = [
    '#type' => 'actions',
    'submit' => [
      '#type' => 'submit',
      '#value' => $this
        ->t('Save'),
      '#button_type' => 'primary',
      '#name' => 'Save',
    ],
    'submit_cancel' => [
      '#type' => 'submit',
      '#weight' => 99,
      '#value' => $this
        ->t('Cancel'),
      '#name' => 'Cancel',
      '#limit_validation_errors' => [],
    ],
  ];
  return $form;
}