You are here

public function EckEntityTypeFormBase::buildForm in Entity Construction Kit (ECK) 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 EntityForm::buildForm

2 calls to EckEntityTypeFormBase::buildForm()
EckEntityTypeAddForm::buildForm in src/Form/EntityType/EckEntityTypeAddForm.php
Form constructor.
EckEntityTypeEditForm::buildForm in src/Form/EntityType/EckEntityTypeEditForm.php
Form constructor.
2 methods override EckEntityTypeFormBase::buildForm()
EckEntityTypeAddForm::buildForm in src/Form/EntityType/EckEntityTypeAddForm.php
Form constructor.
EckEntityTypeEditForm::buildForm in src/Form/EntityType/EckEntityTypeEditForm.php
Form constructor.

File

src/Form/EntityType/EckEntityTypeFormBase.php, line 60

Class

EckEntityTypeFormBase
Class EckEntityTypeFormBase.

Namespace

Drupal\eck\Form\EntityType

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Get the from from the base class.
  $form = parent::buildForm($form, $form_state);
  $eck_entity_type = $this->entity;

  // Build the form.
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $eck_entity_type
      ->label(),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine name'),
    '#maxlength' => 32,
    '#default_value' => $eck_entity_type
      ->id(),
    '#machine_name' => [
      'exists' => [
        $this,
        'exists',
      ],
      'replace_pattern' => '([^a-z0-9_]+)|(^custom$)',
      'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".',
    ],
    '#disabled' => !$eck_entity_type
      ->isNew(),
  ];
  $form['base_fields'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Available base fields'),
  ];
  $config = \Drupal::config('eck.eck_entity_type.' . $eck_entity_type
    ->id());
  foreach ([
    'created',
    'changed',
    'uid',
    'title',
    'status',
  ] as $field) {
    $title = $field === 'uid' ? 'author' : $field;
    $form['base_fields'][$field] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('%field field', [
        '%field' => ucfirst($title),
      ]),
      '#default_value' => $config
        ->get($field),
    ];
  }
  return $form;
}