You are here

public function FlickityGroupDisplayForm::buildForm in Flickity Carousel 8

Same name and namespace in other branches
  1. 8.2 src/Form/FlickityGroupDisplayForm.php \Drupal\flickity\Form\FlickityGroupDisplayForm::buildForm()
  2. 3.0.x src/Form/FlickityGroupDisplayForm.php \Drupal\flickity\Form\FlickityGroupDisplayForm::buildForm()

.

Overrides FormInterface::buildForm

File

src/Form/FlickityGroupDisplayForm.php, line 29
Contains \Drupal\flickity\Form\FlickityGroupDisplayForm.

Class

FlickityGroupDisplayForm
Implements a display form; because vertical tabs for settings groups looks sweet as.

Namespace

Drupal\flickity\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $table = array(
    '#type' => 'table',
    '#header' => array(
      'Name',
      'Description',
      'Value',
    ),
  );
  $form['settings'] = array(
    '#type' => 'vertical_tabs',
    '#title' => t('Flickity settings groups'),
    '#parents' => [
      'settings',
    ],
  );

  // Retrieve config definitions.
  $definitions = \Drupal::service('config.typed')
    ->getDefinition('flickity.group.default');
  $settings = $definitions['mapping']['settings']['mapping'];

  // Retrieve config entity values.
  $groups = flickity_load_multiple();
  foreach ($groups as $group) {
    $form[$group
      ->id()] = array(
      '#type' => 'details',
      '#title' => t('@title', array(
        '@title' => $group
          ->label(),
      )),
      '#group' => 'settings',
    );
    $form[$group
      ->id()]['table'] = $table;
    foreach ($group
      ->getSettings() as $name => $value) {
      $form[$group
        ->id()]['table']['#rows'][] = array(
        'name' => t('@label', array(
          '@label' => $settings[$name]['label'],
        )),
        'description' => t('@text', array(
          '@text' => $settings[$name]['text'],
        )),
        'value' => $value,
      );
    }
    $form[$group
      ->id()]['actions'] = array(
      '#type' => 'container',
    );
    $form[$group
      ->id()]['actions']['edit'] = array(
      '#type' => 'submit',
      '#name' => $group
        ->id(),
      '#value' => 'Edit',
    );
  }
  return $form;
}