You are here

public function SlideGroupBaseForm::buildForm in Drupal Slider 8

Same name and namespace in other branches
  1. 8.2 src/Form/SlideGroupBaseForm.php \Drupal\drupal_slider\Form\SlideGroupBaseForm::buildForm()

Function buildForm.

Overrides EntityForm::buildForm

2 calls to SlideGroupBaseForm::buildForm()
SlideGroupAddForm::buildForm in src/Form/SlideGroupAddForm.php
Function buildForm.
SlideGroupEditForm::buildForm in src/Form/SlideGroupEditForm.php
Function buildForm.
2 methods override SlideGroupBaseForm::buildForm()
SlideGroupAddForm::buildForm in src/Form/SlideGroupAddForm.php
Function buildForm.
SlideGroupEditForm::buildForm in src/Form/SlideGroupEditForm.php
Function buildForm.

File

src/Form/SlideGroupBaseForm.php, line 43

Class

SlideGroupBaseForm
Class SlideGroupBaseForm.

Namespace

Drupal\drupal_slider\Form

Code

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

  // Get anything we need from the base class.
  $form = parent::buildForm($form, $form_state);
  $slideGroup = $this->entity;
  $form['#tree'] = TRUE;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Slide Group Name'),
    '#maxlength' => 255,
    '#default_value' => $slideGroup
      ->label(),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine name'),
    '#default_value' => $slideGroup
      ->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' => !$slideGroup
      ->isNew(),
  ];
  $form['slides'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Slide number'),
      $this
        ->t('Slides'),
      $this
        ->t('Weight'),
    ],
    '#empty' => $this
      ->t('Sorry, There are no groups!'),
    '#prefix' => '<div id="names-fieldset-wrapper">',
    '#suffix' => '</div>',
    // TableDrag: Each array value is a list of callback arguments for
    // drupal_add_tabledrag(). The #id of the table is automatically
    // prepended; if there is none, an HTML ID is auto-generated.
    '#tabledrag' => [
      [
        'action' => 'order',
        'relationship' => 'sibling',
        'group' => 'table-sort-weight',
      ],
    ],
  ];
  return $form;
}