You are here

public function JuiceboxDisplayStyle::buildOptionsForm in Juicebox HTML5 Responsive Image Galleries 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/style/JuiceboxDisplayStyle.php \Drupal\juicebox\Plugin\views\style\JuiceboxDisplayStyle::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides StylePluginBase::buildOptionsForm

File

src/Plugin/views/style/JuiceboxDisplayStyle.php, line 146

Class

JuiceboxDisplayStyle
Plugin implementation of the 'juicebox' display style.

Namespace

Drupal\juicebox\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $settings = $this->options;

  // Get the active field options.
  $options = $this
    ->confGetFieldSources();
  $missing_field_warning = '';
  if (empty($options['field_options_images'])) {
    $missing_field_warning = $this
      ->t('<strong>You must add a field of type image, file or file ID to your view display before this value can be set.</strong><br/>');
  }

  // Add the view-specific elements.
  $form['image_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Image Source'),
    '#default_value' => $settings['image_field'],
    '#description' => $this
      ->t('The field source to use for each image in the gallery. Must be an image field, file field or a file ID. If using a multivalued field (*) only the <em>first</em> value from each entity will be used.'),
    '#suffix' => $missing_field_warning,
    '#options' => $options['field_options_images'],
    '#empty_option' => $this
      ->t('- Select -'),
  ];
  $form['thumb_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Thumbnail Source'),
    '#default_value' => $settings['thumb_field'],
    '#description' => $this
      ->t('The field source to use for each thumbnail in the gallery. Must be an image field, file field or a file ID. Typically you will choose the same value that was set in the "Image Source" option above.'),
    '#suffix' => $missing_field_warning,
    '#options' => $options['field_options_images'],
    '#empty_option' => $this
      ->t('- Select -'),
  ];
  $form['image_field_style'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Image Field Style'),
    '#default_value' => $settings['image_field_style'],
    '#description' => $this
      ->t('The style formatter for the image. Any formatting settings configured on the field itself will be ignored and this style setting will always be used.'),
    '#options' => $this->juicebox
      ->confBaseStylePresets(),
    '#empty_option' => $this
      ->t('None (original image)'),
  ];
  $form['thumb_field_style'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Thumbnail Field Style'),
    '#default_value' => $settings['thumb_field_style'],
    '#description' => $this
      ->t('The style formatter for the thumbnail. Any formatting settings configured on the field itself will be ignored and this style setting will always be used.'),
    '#options' => $this->juicebox
      ->confBaseStylePresets(FALSE),
    '#empty_option' => $this
      ->t('None (original image)'),
  ];
  $form['title_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Title Field'),
    '#default_value' => $settings['title_field'],
    '#description' => $this
      ->t("The view's field that should be used for the title of each image in the gallery. Any formatting settings configured on the field itself will be respected."),
    '#options' => $options['field_options'],
    '#empty_option' => $this
      ->t('None'),
  ];
  $form['caption_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Caption Field'),
    '#default_value' => $settings['caption_field'],
    '#description' => $this
      ->t("The view's field that should be used for the caption of each image in the gallery. Any formatting settings configured on the field itself will be respected."),
    '#options' => $options['field_options'],
    '#empty_option' => $this
      ->t('None'),
  ];
  $form['show_title'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show Gallery Title'),
    '#default_value' => $settings['show_title'],
    '#description' => $this
      ->t('Show the view display title as the gallery title.'),
  ];

  // Add the common form elements.
  $form = $this->juicebox
    ->confBaseForm($form, $settings);

  // Add view-sepcific field options for the linkURL setting.
  $linkurl_field_options = [];
  foreach ($options['field_options'] as $field_key => $field_name) {
    $linkurl_field_options[$field_key] = $this
      ->t('Field') . ' - ' . $field_name;
  }
  $form['linkurl_source']['#description'] = $form['linkurl_source']['#description'] . '</br><strong>' . $this
    ->t('If using a field source it must render a properly formatted URL and nothing else.') . '</strong>';
  $form['linkurl_source']['#options'] = array_merge($form['linkurl_source']['#options'], $linkurl_field_options);
}