You are here

function picture_field_formatter_settings_picture_form in Picture 7.2

Helper function.

See also

picture_field_formatter_settings_form()

File

./picture.module, line 453
Picture formatter.

Code

function picture_field_formatter_settings_picture_form($field, $instance, $settings) {
  $options = picture_get_mapping_options();
  if ($options) {
    $element['picture_mapping'] = array(
      '#title' => t('Picture mapping'),
      '#type' => 'select',
      '#default_value' => isset($settings['picture_mapping']) ? $settings['picture_mapping'] : '',
      '#required' => TRUE,
      '#options' => picture_get_mapping_options(),
    );
  }
  else {
    $element['picture_mapping'] = array(
      '#title' => t('Picture mapping'),
      '#type' => 'item',
      '#markup' => t('There are no picture groups defined. !create_link.', array(
        '!create_link' => l(t('Create a picture mapping'), 'admin/config/media/picture/add'),
      )),
    );
  }
  $image_styles = image_style_options(FALSE);
  $element['fallback_image_style'] = array(
    '#title' => t('Fallback image style'),
    '#type' => 'select',
    '#default_value' => $settings['fallback_image_style'],
    '#empty_option' => t('Automatic'),
    '#options' => $image_styles + array(
      PICTURE_EMPTY_IMAGE => t('Empty image'),
      PICTURE_ORIGINAL_IMAGE => t('Original image'),
    ),
  );
  $element['lazyload'] = array(
    '#title' => t('Picture lazyload'),
    '#description' => t('Image will be rendered when it appears in viewport, helps to optimize page load speed.'),
    '#type' => 'checkbox',
    '#default_value' => $settings['lazyload'] ? $settings['lazyload'] : FALSE,
  );
  $element['lazyload_aspect_ratio'] = array(
    '#title' => t('Keep aspect ratio'),
    '#type' => 'checkbox',
    '#description' => t('Preserve the space for the image being lazyloaded to avoid layout reflows. <br /> Image ratio is defined per breakpoint, make sure all images from srcset have the same ratio. <br />Output example: !example', array(
      '!example' => htmlentities('<source media="(...)" data-srcset="image_400x200.jpg x1, image_800x400.jpg x2, image_1200x600.jpg x3" data-aspectratio="2" />'),
    )),
    '#default_value' => !empty($settings['lazyload_aspect_ratio']),
    '#states' => array(
      'visible' => array(
        ':input[name="fields[field_image][settings_edit_form][settings][lazyload]"]' => array(
          'checked' => TRUE,
        ),
        ':input[name="fields[field_image][settings_edit_form][settings][fallback_image_style]"]' => array(
          'value' => PICTURE_EMPTY_IMAGE,
        ),
      ),
    ),
  );
  $link_types = picture_link_types($instance);
  $element['image_link'] = array(
    '#title' => t('Link image to'),
    '#type' => 'select',
    '#default_value' => $settings['image_link'],
    '#empty_option' => t('Nothing'),
    '#options' => $link_types,
    '#attributes' => array(
      'class' => array(
        'picture-image-link',
      ),
    ),
  );
  if (module_exists('colorbox')) {

    // Settings for the colorbox option.
    $element['colorbox_settings'] = array(
      '#type' => 'fieldset',
      '#tree' => TRUE,
      '#title' => t('Colorbox settings'),
      '#collapsed' => FALSE,
      '#collapsible' => TRUE,
      '#states' => array(
        'visible' => array(
          ':input[name$="' . $field['field_name'] . '][settings_edit_form][settings][image_link]"].picture-image-link' => array(
            'value' => 'colorbox',
          ),
        ),
      ),
    );
    $element['colorbox_settings']['colorbox_group'] = array(
      '#title' => t('Colorbox picture mapping'),
      '#type' => 'select',
      '#default_value' => $settings['colorbox_settings']['colorbox_group'],
      '#required' => FALSE,
      '#options' => picture_get_mapping_options(),
    );
    $gallery = array(
      'post' => t('Per post gallery'),
      'page' => t('Per page gallery'),
      'field_post' => t('Per field in post gallery'),
      'field_page' => t('Per field in page gallery'),
      'custom' => t('Custom'),
      'none' => t('No gallery'),
    );
    $element['colorbox_settings']['colorbox_gallery'] = array(
      '#title' => t('Gallery (image grouping)'),
      '#type' => 'select',
      '#default_value' => $settings['colorbox_settings']['colorbox_gallery'],
      '#options' => $gallery,
      '#description' => t('How Colorbox should group the image galleries.'),
      '#attributes' => array(
        'class' => array(
          'picture-colorbox-gallery',
        ),
      ),
    );
    $element['colorbox_settings']['colorbox_gallery_custom'] = array(
      '#title' => t('Custom gallery'),
      '#type' => 'textfield',
      '#maxlength' => 32,
      '#default_value' => $settings['colorbox_settings']['colorbox_gallery_custom'],
      '#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, hyphen and underscores.'),
      '#element_validate' => array(
        'colorbox_gallery_custom_validate',
      ),
      '#required' => FALSE,
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings][colorbox_settings][colorbox_gallery]"].picture-colorbox-gallery' => array(
            'value' => 'custom',
          ),
        ),
      ),
    );
    $caption = array(
      'auto' => t('Automatic'),
      'title' => t('Title text'),
      'alt' => t('Alt text'),
      'node_title' => t('Content title'),
      'custom' => t('Custom (with tokens)'),
      'none' => t('None'),
    );
    $element['colorbox_settings']['colorbox_caption'] = array(
      '#title' => t('Caption'),
      '#type' => 'select',
      '#default_value' => $settings['colorbox_settings']['colorbox_caption'],
      '#options' => $caption,
      '#description' => t('Automatic will use the first none empty value of the title, the alt text and the content title.'),
      '#attributes' => array(
        'class' => array(
          'picture-colorbox-caption',
        ),
      ),
    );
    $element['colorbox_settings']['colorbox_caption_custom'] = array(
      '#title' => t('Custom caption'),
      '#type' => 'textfield',
      '#default_value' => $settings['colorbox_settings']['colorbox_caption_custom'],
      '#states' => array(
        'visible' => array(
          ':input[name$="[settings][colorbox_settings][colorbox_caption]"].picture-colorbox-caption' => array(
            'value' => 'custom',
          ),
        ),
      ),
    );

    // Allow users to hide or set a custom recursion limit.
    // The module token_tweaks sets a global recursion limit that can not be
    // bypassed.
    if (module_exists('token') && ($recursion_limit = min(variable_get('token_tree_recursion_limit', 3), variable_get('colorbox_token_recursion_limit', 3)))) {
      $element['colorbox_settings']['colorbox_token'] = array(
        '#type' => 'fieldset',
        '#title' => t('Replacement patterns'),
        '#theme' => 'token_tree',
        '#token_types' => array(
          $instance['entity_type'],
          'file',
        ),
        '#recursion_limit' => $recursion_limit,
        '#dialog' => TRUE,
        '#states' => array(
          'visible' => array(
            ':input[name$="[settings][colorbox_settings][colorbox_caption]"].picture-colorbox-caption' => array(
              'value' => 'custom',
            ),
          ),
        ),
      );
    }
    else {
      $element['colorbox_settings']['colorbox_token'] = array(
        '#type' => 'fieldset',
        '#title' => t('Replacement patterns'),
        '#description' => '<strong class="error">' . t('For token support the <a href="@token_url">token module</a> must be installed.', array(
          '@token_url' => 'http://drupal.org/project/token',
        )) . '</strong>',
        '#states' => array(
          'visible' => array(
            ':input[name$="[settings][colorbox_settings][colorbox_caption]"].picture-colorbox-caption' => array(
              'value' => 'custom',
            ),
          ),
        ),
      );
    }
  }
  return $element;
}