You are here

public function BlazyAdminBase::openingForm in Blazy 8.2

Same name and namespace in other branches
  1. 8 src/Form/BlazyAdminBase.php \Drupal\blazy\Form\BlazyAdminBase::openingForm()
  2. 7 src/Form/BlazyAdminBase.php \Drupal\blazy\Form\BlazyAdminBase::openingForm()

Returns shared form elements across field formatter and Views.

2 calls to BlazyAdminBase::openingForm()
BlazyAdminExtended::openingForm in src/Dejavu/BlazyAdminExtended.php
Returns shared form elements across field formatter and Views.
BlazyAdminFormatter::buildSettingsForm in src/Form/BlazyAdminFormatter.php
Defines re-usable form elements.
1 method overrides BlazyAdminBase::openingForm()
BlazyAdminExtended::openingForm in src/Dejavu/BlazyAdminExtended.php
Returns shared form elements across field formatter and Views.

File

src/Form/BlazyAdminBase.php, line 138

Class

BlazyAdminBase
A base for blazy admin integration to have re-usable methods in one place.

Namespace

Drupal\blazy\Form

Code

public function openingForm(array &$form, &$definition = []) {
  $this->blazyManager
    ->getModuleHandler()
    ->alter('blazy_form_element_definition', $definition);

  // Display style: column, plain static grid, slick grid, slick carousel.
  // https://drafts.csswg.org/css-multicol
  if (!empty($definition['style'])) {
    $form['style'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Display style'),
      '#description' => $this
        ->t('Either <strong>CSS3 Columns</strong> (experimental pure CSS Masonry) or <strong>Grid Foundation</strong> requires <strong>Grid</strong>. Difference: <strong>Columns</strong> is best with irregular image sizes (scale width, empty height), affects the natural order of grid items. <strong>Grid</strong> with regular cropped ones. Unless required, leave empty to use default formatter, or style.'),
      '#enforced' => TRUE,
      '#empty_option' => '- None -',
      '#options' => [
        'column' => $this
          ->t('CSS3 Columns'),
        'grid' => $this
          ->t('Grid Foundation'),
      ],
      '#required' => !empty($definition['grid_required']),
      '#weight' => -112,
      '#wrapper_attributes' => [
        'class' => [
          'form-item--style',
          'form-item--tooltip-bottom',
        ],
      ],
    ];
  }
  if (!empty($definition['skins'])) {
    $form['skin'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Skin'),
      '#options' => $definition['skins'],
      '#enforced' => TRUE,
      '#description' => $this
        ->t('Skins allow various layouts with just CSS. Some options below depend on a skin. Leave empty to DIY. Or use the provided hook_info() and implement the skin interface to register ones.'),
      '#weight' => -107,
    ];
  }
  if (!empty($definition['background'])) {
    $form['background'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Use CSS background'),
      '#description' => $this
        ->t('Check this to turn the image into CSS background. This opens up the goodness of CSS, such as background cover, fixed attachment, etc. <br /><strong>Important!</strong> Requires an Aspect ratio, otherwise collapsed containers. Unless explicitly removed such as for GridStack which manages its own problem, or a min-height is added manually to <strong>.b-bg</strong> selector.'),
      '#weight' => -98,
    ];
  }
  if (!empty($definition['layouts'])) {
    $form['layout'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Layout'),
      '#options' => $definition['layouts'],
      '#description' => $this
        ->t('Requires a skin. The builtin layouts affects the entire items uniformly. Leave empty to DIY.'),
      '#weight' => 2,
    ];
  }
  if (!empty($definition['captions'])) {
    $form['caption'] = [
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Caption fields'),
      '#options' => $definition['captions'],
      '#description' => $this
        ->t('Enable any of the following fields as captions. These fields are treated and wrapped as captions.'),
      '#weight' => 80,
      '#attributes' => [
        'class' => [
          'form-wrapper--caption',
        ],
      ],
    ];
  }
  if (!empty($definition['target_type']) && !empty($definition['view_mode'])) {
    $form['view_mode'] = $this
      ->baseForm($definition)['view_mode'];
  }
  $weight = -99;
  foreach (Element::children($form) as $key) {
    if (!isset($form[$key]['#weight'])) {
      $form[$key]['#weight'] = ++$weight;
    }
  }
}