You are here

YamlFormFlexbox.php in YAML Form 8

File

src/Plugin/YamlFormElement/YamlFormFlexbox.php
View source
<?php

namespace Drupal\yamlform\Plugin\YamlFormElement;

use Drupal\Core\Form\FormStateInterface;

/**
 * Provides a 'flexbox' element.
 *
 * @YamlFormElement(
 *   id = "yamlform_flexbox",
 *   label = @Translation("Flexbox layout"),
 *   category = @Translation("Containers"),
 *   states_wrapper = TRUE,
 * )
 */
class YamlFormFlexbox extends Container {

  /**
   * {@inheritdoc}
   */
  public function getDefaultProperties() {
    return parent::getDefaultProperties() + [
      // Flexbox.
      'align_items' => 'flex-start',
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function build($format, array &$element, $value, array $options = []) {
    return $value;
  }

  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form, $form_state);
    $form['flexbox'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Flexbox settings'),
    ];
    $form['flexbox']['align_items'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Align items'),
      '#options' => [
        'flex-start' => $this
          ->t('Top (flex-start)'),
        'flex-end' => $this
          ->t('Bottom (flex-end)'),
        'center' => $this
          ->t('Center (center)'),
      ],
      '#required' => TRUE,
    ];
    return $form;
  }

}

Classes

Namesort descending Description
YamlFormFlexbox Provides a 'flexbox' element.