Same name and namespace in other branches
  1. 7.x-1.x colorbox.module \colorbox_field_formatter_settings_form() 1 comment

Implements hook_field_formatter_settings_form().

File

./colorbox.module, line 331

Code

function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
    $display = $instance['display'][$view_mode];
    $settings = $display['settings'];
    $image_styles = image_style_options(FALSE);
    $image_styles_hide = $image_styles;
    $image_styles_hide['hide'] = t('Hide (do not display image)');
    $element['colorbox_node_style'] = array(
        '#title' => t('Content image style'),
        '#type' => 'select',
        '#default_value' => $settings['colorbox_node_style'],
        '#empty_option' => t('None (original image)'),
        '#options' => $image_styles_hide,
        '#description' => t('Image style to use in the content.'),
    );
    $element['colorbox_node_style_first'] = array(
        '#title' => t('Content image style for first image'),
        '#type' => 'select',
        '#default_value' => $settings['colorbox_node_style_first'],
        '#empty_option' => t('No special style.'),
        '#options' => $image_styles,
        '#description' => t('Image style to use in the content for the first image.'),
    );
    $element['colorbox_image_style'] = array(
        '#title' => t('Colorbox image style'),
        '#type' => 'select',
        '#default_value' => $settings['colorbox_image_style'],
        '#empty_option' => t('None (original image)'),
        '#options' => $image_styles,
        '#description' => t('Image style to use in the Colorbox.'),
    );
    $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_gallery'] = array(
        '#title' => t('Gallery (image grouping)'),
        '#type' => 'select',
        '#default_value' => $settings['colorbox_gallery'],
        '#options' => $gallery,
        '#description' => t('How Colorbox should group the image galleries.'),
    );
    $element['colorbox_gallery_custom'] = array(
        '#title' => t('Custom gallery'),
        '#type' => 'textfield',
        '#maxlength' => 32,
        '#default_value' => $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_edit_form][settings][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_caption'] = array(
        '#title' => t('Caption'),
        '#type' => 'select',
        '#default_value' => $settings['colorbox_caption'],
        '#options' => $caption,
        '#description' => t('Automatic will use the first non-empty value of the title, the alt text and the content title.'),
    );
    $element['colorbox_caption_custom'] = array(
        '#title' => t('Custom caption'),
        '#type' => 'textfield',
        '#default_value' => $settings['colorbox_caption_custom'],
        '#states' => array(
            'visible' => array(
                ':input[name$="[settings_edit_form][settings][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)))) {
        // File entities do not have $field, only $instance.
        if (!empty($field)) {
            $token_types = array_merge(array_keys($field['bundles']), array(
                'file',
            ));
        }
        else {
            $token_types = array(
                $instance['entity_type'],
                'file',
            );
        }
        $element['colorbox_token'] = array(
            '#type' => 'fieldset',
            '#title' => t('Replacement patterns'),
            '#theme' => 'token_tree',
            '#token_types' => $token_types,
            '#recursion_limit' => $recursion_limit,
            '#dialog' => TRUE,
            '#states' => array(
                'visible' => array(
                    ':input[name$="[settings_edit_form][settings][colorbox_caption]"]' => array(
                        'value' => 'custom',
                    ),
                ),
            ),
        );
    }
    else {
        $element['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_edit_form][settings][colorbox_caption]"]' => array(
                        'value' => 'custom',
                    ),
                ),
            ),
        );
    }
    return $element;
}