You are here

public function MasonryService::buildSettingsForm in Masonry API 8

Build the masonry setting configuration form.

Parameters

array (optional): The default values for the form.

Return value

array The form

File

src/Services/MasonryService.php, line 225
Masonry service file.

Class

MasonryService
Wrapper methods for Masonry API methods.

Namespace

Drupal\masonry\Services

Code

public function buildSettingsForm($default_values = []) {

  // Load module default values if empty.
  if (empty($default_values)) {
    $default_values = $this
      ->getMasonryDefaultOptions();
  }
  $form['layoutColumnWidth'] = [
    '#type' => 'textfield',
    '#title' => t('Column width'),
    '#description' => t("The width of each column, enter pixels, percentage, or string of css selector"),
    '#default_value' => $default_values['layoutColumnWidth'],
  ];
  $form['layoutColumnWidthUnit'] = [
    '#type' => 'radios',
    '#title' => t('Column width units'),
    '#description' => t("The units to use for the column width."),
    '#options' => [
      'px' => t("Pixels"),
      '%' => t("Percentage (of container's width)"),
      'css' => t("CSS selector (you must configure your css to set widths for .masonry-item)"),
    ],
    '#default_value' => $default_values['layoutColumnWidthUnit'],
  ];
  $form['gutterWidth'] = [
    '#type' => 'textfield',
    '#title' => t('Gutter width'),
    '#description' => t("The spacing between each column."),
    '#default_value' => $default_values['gutterWidth'],
    '#size' => 4,
    '#maxlength' => 3,
    '#field_suffix' => t('px'),
  ];
  $form['stampSelector'] = [
    '#type' => 'textfield',
    '#title' => t('Stamp Selector'),
    '#description' => t("Specifies which elements are stamped within the layout using css selector"),
    '#default_value' => $default_values['stampSelector'],
  ];
  $form['isLayoutResizable'] = [
    '#type' => 'checkbox',
    '#title' => t('Resizable'),
    '#description' => t("Automatically rearrange items when the container is resized."),
    '#default_value' => $default_values['isLayoutResizable'],
  ];
  $form['isLayoutAnimated'] = [
    '#type' => 'checkbox',
    '#title' => t('Animated'),
    '#description' => t("Animate item rearrangements."),
    '#default_value' => $default_values['isLayoutAnimated'],
    '#states' => [
      'visible' => [
        'input.form-checkbox[name*="isLayoutResizable"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['layoutAnimationDuration'] = [
    '#type' => 'textfield',
    '#title' => t('Animation duration'),
    '#description' => t("The duration of animations (1000 ms = 1 sec)."),
    '#default_value' => $default_values['layoutAnimationDuration'],
    '#size' => 5,
    '#maxlength' => 4,
    '#field_suffix' => t('ms'),
    '#states' => [
      'visible' => [
        'input.form-checkbox[name*="isLayoutResizable"]' => [
          'checked' => TRUE,
        ],
        'input.form-checkbox[name*="isLayoutAnimated"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['isLayoutFitsWidth'] = [
    '#type' => 'checkbox',
    '#title' => t('Fit width'),
    '#description' => t("Sets the width of the container to the nearest column. Ideal for centering Masonry layouts. See the <a href='http://masonry.desandro.com/demos/centered.html'>'Centered' demo</a> for more information."),
    '#default_value' => $default_values['isLayoutFitsWidth'],
  ];
  $form['isLayoutImagesLoadedFirst'] = [
    '#type' => 'checkbox',
    '#title' => t('Load images first'),
    '#description' => t("Load all images first before triggering Masonry."),
    '#default_value' => $default_values['isLayoutImagesLoadedFirst'],
  ];
  $form['isLayoutImagesLazyLoaded'] = [
    '#type' => 'checkbox',
    '#title' => t('Add listener for lazy loaded images.'),
    '#description' => t("If using the lazysizes library, you should probably activate this option."),
    '#default_value' => $default_values['isLayoutImagesLazyLoaded'],
  ];
  $form['isItemsPositionInPercent'] = [
    '#type' => 'checkbox',
    '#title' => t('Percent position'),
    '#description' => t("Sets item positions in percent values, rather than pixel values. Checking this will works well with percent-width items, as items will not transition their position on resize. See the <a href='http://masonry.desandro.com/options.html#percentposition'>masonry doc</a> for more information."),
    '#default_value' => $default_values['isItemsPositionInPercent'],
  ];

  // Allow other modules and themes to alter the form.
  $this->moduleHandler
    ->alter('masonry_options_form', $form, $default_values);
  $this->themeManager
    ->alter('masonry_options_form', $form, $default_values);
  return $form;
}