You are here

function picture_file_formatter_picture_settings in Picture 7.2

Same name and namespace in other branches
  1. 7 picture.file_entity_1.inc \picture_file_formatter_picture_settings()

Settings callback for hook_file_formatter_info().

1 string reference to 'picture_file_formatter_picture_settings'
picture_file_formatter_info in ./picture.file_entity_1.inc
Implements hook_file_formatter_info().

File

./picture.file_entity_1.inc, line 129
Hooks and functions to support version 1 of the File Entity module.

Code

function picture_file_formatter_picture_settings($form, &$form_state, $settings) {
  $picture_group_options = array();
  $picture_mappings = picture_mapping_load_all();
  if ($picture_mappings && !empty($picture_mappings)) {
    foreach ($picture_mappings as $machine_name => $picture_mapping) {
      $breakpoint_group = $picture_mapping
        ->getBreakpointGroup();
      if ($breakpoint_group) {
        $picture_group_options[$machine_name] = $picture_mapping->label;
      }
    }
  }
  $element['picture_group'] = array(
    '#title' => t('Picture group'),
    '#type' => 'select',
    '#default_value' => $settings['picture_group'],
    '#required' => TRUE,
    '#options' => $picture_group_options,
  );
  $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'),
    ),
  );
  $element['lazyload'] = array(
    '#title' => t('Picture lazyload'),
    '#type' => 'checkbox',
    '#description' => t('Image will be rendered when it appears in viewport, helps to optimize page load speed.'),
    '#default_value' => !empty($settings['lazyload']),
  );
  $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="displays[file_picture][settings][lazyload]"]' => array(
          'checked' => TRUE,
        ),
        ':input[name="displays[file_picture][settings][fallback_image_style]"]' => array(
          'value' => PICTURE_EMPTY_IMAGE,
        ),
      ),
    ),
  );
  $element['alt'] = array(
    '#title' => t('Alt attribute'),
    '#description' => t('The text to use as value for the <em>img</em> tag <em>alt</em> attribute.'),
    '#type' => 'textfield',
    '#default_value' => $settings['alt'],
  );

  // Allow the setting of the title attribute.
  $element['title'] = array(
    '#title' => t('Title attribute'),
    '#description' => t('The text to use as value for the <em>img</em> tag <em>title</em> attribute.'),
    '#type' => 'textfield',
    '#default_value' => $settings['title'],
  );
  return $element;
}