You are here

public function LabeledFormTrait::addLabelFields in Extensible BBCode 8.3

Same name and namespace in other branches
  1. 4.0.x src/Form/LabeledFormTrait.php \Drupal\xbbcode\Form\LabeledFormTrait::addLabelFields()

Add label fields to the form array.

Parameters

array $form: Form array.

Return value

array Form array.

2 calls to LabeledFormTrait::addLabelFields()
TagFormBase::form in src/Form/TagFormBase.php
Gets the actual form array to be built.
TagSetForm::form in src/Form/TagSetForm.php
Gets the actual form array to be built.

File

src/Form/LabeledFormTrait.php, line 40

Class

LabeledFormTrait
Helper function for adding label fields to an entity form.

Namespace

Drupal\xbbcode\Form

Code

public function addLabelFields(array $form) : array {
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#default_value' => $this
      ->getEntity()
      ->label(),
    '#maxlength' => 255,
    '#required' => TRUE,
    '#weight' => -30,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $this
      ->getEntity()
      ->id(),
    '#maxlength' => 255,
    '#machine_name' => [
      'exists' => [
        $this,
        'exists',
      ],
      'source' => [
        'label',
      ],
    ],
    '#disabled' => !$this
      ->getEntity()
      ->isNew(),
    '#weight' => -20,
  ];
  return $form;
}