You are here

public function CollageFormatter::settingsForm in Collage Formatter 8

Returns a form to configure settings for the formatter.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form elements for the formatter settings.

Overrides ImageFormatter::settingsForm

File

src/Plugin/Field/FieldFormatter/CollageFormatter.php, line 71
Contains \Drupal\collageformatter\src\Plugin\Field\FieldFormatter\CollageFormatter.

Class

CollageFormatter
Plugin implementation of the 'collageformatter' formatter.

Namespace

Drupal\collageformatter\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $options_0_50 = array_combine(range(0, 50), range(0, 50));
  $options_1_50 = array_combine(range(1, 50), range(1, 50));
  $settings = $this
    ->getSettings();
  $form['collage_number'] = [
    '#type' => 'select',
    '#title' => t('Number of collages'),
    '#title_display' => 'invisible',
    '#options' => $options_1_50,
    '#default_value' => $settings['collage_number'],
    '#field_prefix' => t('Generate'),
    '#field_suffix' => t('collage(s)'),
    '#prefix' => '<div class="container-inline">',
  ];
  $form['images_per_collage'] = [
    '#type' => 'select',
    '#title' => t('Images per collage'),
    '#title_display' => 'invisible',
    '#options' => $options_1_50,
    '#default_value' => $settings['images_per_collage'],
    '#empty_option' => t('all'),
    '#field_prefix' => t('with'),
    '#field_suffix' => t('image(s) per collage') . ';',
  ];
  $form['images_to_skip'] = [
    '#type' => 'select',
    '#title' => t('Images to skip'),
    '#title_display' => 'invisible',
    '#options' => $options_0_50,
    '#default_value' => $settings['images_to_skip'],
    '#field_prefix' => t('Skip'),
    '#field_suffix' => t('image(s) from the start'),
    '#suffix' => '</div>',
  ];
  $form['collage_orientation'] = [
    '#type' => 'select',
    '#title' => t('Collage orientation'),
    '#description' => t('Select if it should be a wide collage (landscape) or a tall one (portrait).'),
    '#options' => [
      '0' => t('Landscape'),
      '1' => t('Portrait'),
    ],
    '#default_value' => $settings['collage_orientation'],
    '#prefix' => '<div class="container-inline">',
    '#field_suffix' => '</br>',
    '#suffix' => '</div>',
  ];
  $form['collage_width'] = [
    '#type' => 'textfield',
    '#title' => t('Collage width'),
    '#title_display' => 'invisible',
    '#default_value' => $settings['collage_width'],
    '#min' => 0,
    '#size' => 4,
    '#maxlength' => 4,
    '#prefix' => '<div class="container-inline"><strong>' . t('Collage width & height: ') . '</strong>',
    // '#field_prefix' => '<br/>',
    '#field_suffix' => 'x',
  ];
  $form['collage_height'] = [
    '#type' => 'textfield',
    '#title' => t('Collage height'),
    '#title_display' => 'invisible',
    '#description' => t('Total collage width and height with all the borders and gaps. If you specify both then the images will be cropped.'),
    '#default_value' => $settings['collage_height'],
    '#min' => 0,
    '#size' => 4,
    '#maxlength' => 4,
    '#field_suffix' => 'px ',
    '#suffix' => '</div>',
  ];
  $form['collage_border_size'] = [
    '#type' => 'select',
    '#title' => t('Collage border'),
    '#options' => $options_0_50,
    '#default_value' => $settings['collage_border_size'],
    '#field_suffix' => 'px',
    '#prefix' => '<div class="container-inline">',
  ];
  $form['collage_border_color'] = [
    '#type' => 'textfield',
    '#title' => t('Collage border color'),
    '#default_value' => $settings['collage_border_color'],
    '#field_suffix' => '<div class="farbtastic-colorpicker"></div>',
    '#size' => 7,
    '#maxlength' => 7,
    '#suffix' => '</div>',
    '#wrapper_attributes' => [
      'class' => [
        'collageformatter-farbtastic-color-selector',
      ],
    ],
    '#attributes' => [
      'class' => [
        'collageformatter-color-textfield',
      ],
    ],
    '#attached' => [
      'library' => [
        'collageformatter/collageformatter.farbtastic_color_selector',
      ],
    ],
  ];
  $form['gap_size'] = $form['collage_border_size'];
  $form['gap_size']['#title'] = t('Image gap');
  $form['gap_size']['#default_value'] = $settings['gap_size'];
  $form['gap_color'] = $form['collage_border_color'];
  $form['gap_color']['#title'] = t('Image gap color');
  $form['gap_color']['#default_value'] = $settings['gap_color'];
  $form['border_size'] = $form['collage_border_size'];
  $form['border_size']['#title'] = t('Image border');
  $form['border_size']['#default_value'] = $settings['border_size'];
  $form['border_color'] = $form['collage_border_color'];
  $form['border_color']['#title'] = t('Image border color');
  $form['border_color']['#default_value'] = $settings['border_color'];
  $form['image_link'] = [
    '#title' => t('Link image to'),
    '#type' => 'select',
    '#default_value' => $settings['image_link'],
    '#empty_option' => t('Nothing'),
    '#options' => [
      'content' => t('Content'),
      'file' => t('File'),
    ],
    '#prefix' => '<div class="container-inline">',
  ];
  $image_styles = image_style_options(FALSE);
  $form['image_link_image_style'] = [
    '#title' => t('Target image style'),
    '#type' => 'select',
    '#default_value' => $settings['image_link_image_style'],
    '#empty_option' => t('None (original image)'),
    '#options' => $image_styles,
  ];
  $modal_options = [];
  if (\Drupal::moduleHandler()
    ->moduleExists('colorbox')) {
    $modal_options['colorbox'] = t('Colorbox');
  }
  if (\Drupal::moduleHandler()
    ->moduleExists('shadowbox')) {
    $modal_options['shadowbox'] = t('Shadowbox');
  }
  if (\Drupal::moduleHandler()
    ->moduleExists('fancybox')) {
    $modal_options['fancybox'] = t('fancyBox');
  }
  if (\Drupal::moduleHandler()
    ->moduleExists('photobox')) {
    $modal_options['photobox'] = t('Photobox');
  }
  if (\Drupal::moduleHandler()
    ->moduleExists('photoswipe')) {
    $modal_options['photoswipe'] = t('PhotoSwipe');
  }
  if (\Drupal::moduleHandler()
    ->moduleExists('lightbox2')) {
    $modal_options['lightbox2'] = t('Lightbox2');
  }
  $form['image_link_modal'] = [
    '#title' => t('Modal gallery'),
    '#type' => 'select',
    '#default_value' => $settings['image_link_modal'],
    '#empty_option' => t('None'),
    '#options' => $modal_options,
    '#suffix' => '</div>',
  ];
  $form['image_link_class'] = [
    '#type' => 'textfield',
    '#title' => t('Image link class'),
    // '#description' => t('Custom class to add to all image links.'),
    '#default_value' => $settings['image_link_class'],
    '#size' => 30,
    '#prefix' => '<div class="container-inline">',
  ];
  $form['image_link_rel'] = [
    '#type' => 'textfield',
    '#title' => t('Image link rel'),
    // '#description' => t('Custom rel attribute to add to all image links.'),
    '#default_value' => $settings['image_link_rel'],
    '#size' => 30,
    '#suffix' => '</div>',
  ];
  $form['generate_image_derivatives'] = [
    '#type' => 'checkbox',
    '#title' => t('Generate image derivatives'),
    '#description' => t('Generate image derivatives used in the collage while rendering it, before displaying.'),
    '#default_value' => $settings['generate_image_derivatives'],
  ];
  $form['prevent_upscale'] = [
    '#type' => 'checkbox',
    '#title' => t('Prevent images upscaling'),
    '#description' => t('Generated collage dimensions might be smaller.'),
    '#default_value' => $settings['prevent_upscale'],
  ];
  $form['advanced'] = [
    '#type' => 'details',
    '#title' => t('Advanced settings'),
    '#collapsible' => TRUE,
    '#open' => FALSE,
  ];
  $form['advanced']['original_image_reference'] = [
    '#type' => 'radios',
    '#title' => t('Original image reference method'),
    '#description' => t('If you need to add additional image effects to collageformatter image style before the "Collage Formatter" effect then you need to use "Symlink" or "Copy" method.'),
    '#options' => [
      'symlink' => t('Symlink'),
      'fake' => t('Fake image'),
      'copy' => t('Copy'),
    ],
    '#default_value' => $settings['advanced']['original_image_reference'],
  ];
  $form['image_link_image_style']['#states'] = [
    'visible' => [
      ':input[name="fields[field_image][settings_edit_form][settings][image_link]"]' => [
        'value' => 'file',
      ],
    ],
  ];
  $form['image_link_modal']['#states'] = [
    'visible' => [
      ':input[name="fields[field_image][settings_edit_form][settings][image_link]"]' => [
        'value' => 'file',
      ],
    ],
  ];
  $form['image_link_class']['#states'] = [
    'invisible' => [
      ':input[name="fields[field_image][settings_edit_form][settings][image_link]"]' => [
        'value' => '',
      ],
    ],
  ];
  $form['image_link_rel']['#states'] = [
    'invisible' => [
      ':input[name="fields[field_image][settings_edit_form][settings][image_link]"]' => [
        'value' => '',
      ],
    ],
  ];
  return $form;
}