You are here

public function BaseFieldConfigFromBase::buildForm in Apigee Edge 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/BaseFieldConfigFromBase.php, line 74

Class

BaseFieldConfigFromBase
Base form for configuring base fields on Apigee Edge entities.

Namespace

Drupal\apigee_edge\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $base_fields = $this->entityFieldManager
    ->getBaseFieldDefinitions($this
    ->entityType());
  $form['#attached']['library'][] = 'apigee_edge/apigee_edge.admin';
  $form['table'] = [
    '#type' => 'table',
    '#caption' => $this
      ->t('Base field settings'),
    '#header' => [
      $this
        ->t('Field name'),
      $this
        ->t('Required'),
    ],
  ];
  foreach ($base_fields as $name => $base_field) {
    if ($base_field
      ->isDisplayConfigurable('form')) {
      $form['table'][$name] = [
        'name' => [
          '#type' => 'item',
          '#markup' => $base_field
            ->getLabel(),
        ],
        'required' => [
          '#type' => 'checkbox',
          '#title' => $this
            ->t('Required'),
          '#title_display' => 'invisible',
          '#default_value' => $base_field
            ->isRequired(),
        ],
      ];
    }
  }
  foreach ($this
    ->getLockedBaseFields() as $locked) {
    $form['table'][$locked]['required']['#disabled'] = TRUE;
  }
  $form['save'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
  ];
  return $form;
}