You are here

function iframe_field_instance_settings_form in Iframe 7

Implements hook_field_instance_settings_form(). These settings apply only to the iframe field when used in this special content-type. Field XYZ sub-menu "Edit" (Step 3)

File

./iframe.module, line 160
Defines an iframe field with all attributes.

Code

function iframe_field_instance_settings_form($field, $instance) {
  $field_settings = $field['settings'];

  // as defined before in iframe_field_settings_form() ! has preference over instance_settings
  $settings = $instance['settings'];

  // default instance_settings from iframe_field_info
  $form = array();
  if ($field['type'] == 'iframe') {
    $form['width'] = array(
      '#type' => 'textfield',
      '#title' => t('Iframe width'),
      '#default_value' => !empty($settings['width']) ? $settings['width'] : (!empty($field_settings['width']) ? $field_settings['width'] : ''),
      '#description' => t('Iframes need a fixed width and height; only numbers are allowed, or percentage values. (e.g. 500px => "500", 80% => "80%")'),
      //'#disabled' => $has_data,
      '#maxlength' => 4,
      '#size' => 4,
    );
    $form['height'] = array(
      '#type' => 'textfield',
      '#title' => t('Iframe height'),
      '#default_value' => !empty($settings['height']) ? $settings['height'] : (!empty($field_settings['height']) ? $field_settings['height'] : ''),
      '#description' => t('Iframes need a fixed width and height; only numbers are allowed, or percentage values. (e.g. 500px => "500", 80% => "80%")'),
      '#maxlength' => 4,
      '#size' => 4,
    );
    $form['class'] = array(
      '#type' => 'textfield',
      '#title' => t('Additional CSS Class'),
      '#default_value' => !empty($settings['class']) ? $settings['class'] : (!empty($field_settings['class']) ? $field_settings['class'] : ''),
      '#description' => t('When output, this iframe will have this class attribute. Multiple classes should be separated by spaces.'),
    );
    $form['expose_class'] = array(
      '#type' => 'checkbox',
      '#title' => t('Expose Additional CSS Class'),
      '#default_value' => isset($settings['expose_class']) ? (int) $settings['expose_class'] : 1,
      '#description' => t('Allow author to specify an additional class attribute for this iframe.'),
    );
    $form['frameborder'] = array(
      '#type' => 'select',
      '#title' => t('Frameborder'),
      '#options' => array(
        '0' => t('No frameborder'),
        '1' => t('Show frameborder'),
      ),
      '#default_value' => !empty($settings['frameborder']) ? $settings['frameborder'] : (!empty($field_settings['frameborder']) ? $field_settings['frameborder'] : 0),
      '#description' => t('Frameborder is the border arround the iframe. Mostly people want it silent, so the default value for frameborder is 0 = no.'),
    );
    $form['scrolling'] = array(
      '#type' => 'select',
      '#title' => t('Scrolling'),
      '#options' => array(
        'auto' => t('Scrolling automatic'),
        'no' => t('Scrolling disabled'),
        'yes' => t('Scrolling enabled'),
      ),
      '#default_value' => !empty($settings['scrolling']) ? $settings['scrolling'] : (!empty($field_settings['scrolling']) ? $field_settings['scrolling'] : 'auto'),
      '#description' => t('Scrollbars help the user to reach all iframe content despite the real height of the iframe content. Please disable it only if You know what You are doing.'),
    );
    $form['transparency'] = array(
      '#type' => 'select',
      '#title' => t('Transparency'),
      '#options' => array(
        '0' => t('No transparency'),
        '1' => t('Allow transparency'),
      ),
      '#default_value' => !empty($settings['transparency']) ? $settings['transparency'] : (!empty($field_settings['transparency']) ? $field_settings['transparency'] : 0),
      '#description' => t('Allow transparency per CSS in the outer iframe tag. You have to set background-color:transparent in your iframe body tag too!'),
    );
    $form['tokensupport'] = array(
      '#type' => 'select',
      '#title' => t('Token Support'),
      '#options' => array(
        '0' => t('no tokens allowed'),
        '1' => t('tokens only in title field'),
        '2' => t('tokens for title and url field'),
      ),
      '#default_value' => !empty($settings['tokensupport']) ? $settings['tokensupport'] : (!empty($field_settings['tokensupport']) ? $field_settings['tokensupport'] : '0'),
      '#description' => t('Are tokens allowed for users to use in title or URL field?'),
    );
    if (!module_exists('token')) {
      $form['tokensupport']['#description'] .= ' ' . t('Attention: token module is not enabled currently!');
    }
    $form['allowfullscreen'] = array(
      '#type' => 'checkbox',
      '#title' => t('Allow fullscreen'),
      '#default_value' => isset($settings['allowfullscreen']) ? (int) $settings['allowfullscreen'] : 0,
      '#description' => t('Allow author to specify an additional class attribute for this iframe.'),
    );
  }
  return $form;
}