You are here

public function BlazyAdminBase::openingForm in Blazy 7

Same name and namespace in other branches
  1. 8.2 src/Form/BlazyAdminBase.php \Drupal\blazy\Form\BlazyAdminBase::openingForm()
  2. 8 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/Form/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/Form/BlazyAdminExtended.php
Returns shared form elements across field formatter and Views.

File

src/Form/BlazyAdminBase.php, line 78

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 = []) {
  drupal_alter('blazy_form_element_definition', $definition);
  $forms = isset($definition['forms']) ? $definition['forms'] : [];

  // Display style: column, plain static grid, slick grid, slick carousel.
  // https://drafts.csswg.org/css-multicol
  if (!empty($forms['grid'])) {
    $form['style'] = [
      '#type' => 'select',
      '#title' => t('Display style'),
      '#description' => 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,
      '#options' => [
        'column' => t('CSS3 Columns'),
        'grid' => t('Grid Foundation'),
      ],
      '#weight' => -112,
      '#attributes' => [
        'data-blazy-tooltip-direction' => 'bottom',
        'data-blazy-form-item' => 'style',
      ],
      '#required' => !empty($definition['grid_required']),
    ];
  }
  if (!empty($definition['skins'])) {
    $form['skin'] = [
      '#type' => 'select',
      '#title' => t('Skin'),
      '#options' => $definition['skins'],
      '#enforced' => TRUE,
      '#description' => 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' => t('Use CSS background'),
      '#description' => 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 a consistent Aspect ratio, otherwise collapsed containers. Unless a min-height is added manually to <strong>.media--background</strong> selector. Not compatible with Picture image.'),
      '#weight' => -98,
    ];
  }
  if (!empty($definition['layouts'])) {
    $form['layout'] = [
      '#type' => 'select',
      '#title' => t('Layout'),
      '#options' => $definition['layouts'],
      '#description' => 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' => t('Caption fields'),
      '#options' => $definition['captions'],
      '#description' => t('Enable any of the following fields as captions. These fields are treated and wrapped as captions.'),
      '#weight' => 80,
      '#attributes' => [
        'class' => [
          'form-wrapper--caption',
        ],
        'data-blazy-form-item' => 'caption',
      ],
    ];
    if ($this
      ->showAltTitleFieldHint($definition)) {
      $form['caption']['#description'] = $this
        ->showAltTitleFieldHint($definition);
    }
  }
  if (!empty($definition['target_type']) && !empty($definition['use_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;
    }
  }
}