You are here

function backgroundfield_field_instance_settings_form in BackgroundField 7

hook_field_instance_settings_form()

File

./backgroundfield.module, line 48

Code

function backgroundfield_field_instance_settings_form($field, $instance) {

  // image field expects these
  $instance['settings']['alt_field'] = '';
  $instance['settings']['title_field'] = '';
  $instance['settings']['default_image'] = '';

  // Use the image field instance settings form as a basis.
  $form = image_field_instance_settings_form($field, $instance);

  // more convenient variable
  $settings = $instance['settings'];

  // we don't need these, but unsetting them seems to be problematic
  $form['alt_field']['#access'] = FALSE;
  $form['title_field']['#access'] = FALSE;
  $image_styles = image_styles();
  $options = array(
    'no_style' => t('Original Image'),
  );
  foreach ($image_styles as $style => $details) {
    $options[$style] = $details['name'];
  }
  $form['image_style'] = array(
    '#type' => 'select',
    '#title' => t('Image Style'),
    '#default_value' => isset($settings['image_style']) && !empty($settings['image_style']) ? $settings['image_style'] : 'no_style',
    '#description' => t('Select an image style to apply to this image'),
    '#options' => $options,
  );
  $form['css_selector'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS Selector'),
    '#default_value' => isset($settings['css_selector']) && !empty($settings['css_selector']) ? $settings['css_selector'] : 'body',
    '#description' => t(''),
    '#required' => TRUE,
  );
  $form['tokens'] = array(
    '#theme' => 'token_tree',
    '#token_types' => array(
      $instance['entity_type'],
    ),
    // The token types that have specific context. Can be multiple token types like 'term' and/or 'user'
    '#global_types' => TRUE,
    // A boolean TRUE or FALSE whether to include 'global' context tokens like [current-user:*] or [site:*]. Defaults to TRUE.
    '#click_insert' => TRUE,
  );
  $form['css_repeat'] = array(
    '#type' => 'radios',
    '#title' => t('Repeat'),
    '#default_value' => isset($settings['css_repeat']) && !empty($settings['css_repeat']) ? $settings['css_repeat'] : 'repeat',
    '#options' => array(
      'repeat' => t('Repeat'),
      'repeat-x' => t('Repeat Horizontally'),
      'repeat-y' => t('Repeat Vertically'),
      'no-repeat' => t('No Repeat'),
    ),
    '#required' => TRUE,
  );
  $form['css_h_position'] = array(
    '#type' => 'radios',
    '#title' => t('Horizontal Position'),
    '#default_value' => isset($settings['css_h_position']) && !empty($settings['css_h_position']) ? $settings['css_h_position'] : 'left',
    '#options' => array(
      'left' => t('Left'),
      'center' => t('Center'),
      'right' => t('Right'),
    ),
    '#required' => TRUE,
  );
  $form['css_v_position'] = array(
    '#type' => 'radios',
    '#title' => t('Vertical Position'),
    '#default_value' => isset($settings['css_v_position']) && !empty($settings['css_v_position']) ? $settings['css_v_position'] : 'top',
    '#options' => array(
      'top' => t('Top'),
      'center' => t('Center'),
      'bottom' => t('Bottom'),
    ),
    '#required' => TRUE,
  );
  $form['css_attachment'] = array(
    '#type' => 'radios',
    '#title' => t('Attachment'),
    '#default_value' => isset($settings['css_attachment']) && !empty($settings['css_attachment']) ? $settings['css_attachment'] : 'scroll',
    '#options' => array(
      'scroll' => t('Scroll'),
      'fixed' => t('Fixed'),
    ),
    '#required' => TRUE,
  );
  $form['css_size'] = array(
    '#type' => 'textfield',
    '#title' => t('Size'),
    '#description' => t('Enter the CSS3 background-size. Refer to the <a href="@spec">W3 specification</a> for available options.', array(
      '@spec' => url('http://www.w3.org/TR/2011/CR-css3-background-20110215/', array(
        'fragment' => 'the-background-size',
      )),
    )),
    '#default_value' => isset($settings['css_size']) && !empty($settings['css_size']) ? $settings['css_size'] : 'auto',
  );
  $form['css_important'] = array(
    '#type' => 'checkbox',
    '#title' => t('!important'),
    '#description' => t('Check this in order to set the <a href="@important_url">!important declaration</a>.', array(
      '@important_url' => url('http://www.w3.org/TR/CSS21/cascade.htmlr', array(
        'fragment' => 'important-rules',
      )),
    )),
    '#default_value' => isset($settings['css_important']) && $settings['css_important'] ? $settings['css_important'] : 0,
  );
  return $form;
}