You are here

function iframe_field_settings in Iframe 6

Implementation of hook_field_settings(). shown: at general setup of this field type on a content type

File

./iframe.module, line 51
Defines simple iframe field types. based on the cck-module "link" by quicksketch MODULE-Funtions

Code

function iframe_field_settings($op, $field) {
  dmsg(3, 'func iframe_field_settings op=' . $op);
  switch ($op) {
    case 'form':
      $form = array(
        '#theme' => 'iframe_field_settings',
      );
      $form['url'] = array(
        '#type' => 'checkbox',
        '#title' => t('Optional url'),
        '#default_value' => $field['url'],
        '#return_value' => 'optional',
        '#description' => t('If checked, the url field is optional. If the url is ommitted, nothing will be displayed.'),
      );
      $title_options = array(
        'optional' => t('Optional Title'),
        'required' => t('Required Title'),
        'value' => t('Static Title: '),
        'none' => t('No Title'),
      );
      $form['title'] = array(
        '#type' => 'radios',
        '#title' => t('IFrame Title'),
        '#default_value' => isset($field['title']) ? $field['title'] : 'optional',
        '#options' => $title_options,
        '#description' => t('If the iframe title is optional or required, a field will be displayed to the end user. If the iframe title is static, the iframe will always use the same title. If <a href="http://drupal.org/project/token">token module</a> is installed, the static title value may use any other node field as its value. Static and token-based titles may include most inline XHTML tags such as <em>strong</em>, <em>em</em>, <em>img</em>, <em>span</em>, etc.'),
      );
      $form['title_value'] = array(
        '#type' => 'textfield',
        '#default_value' => $field['title_value'],
        '#size' => '46',
      );

      // Add token module replacements if available
      if (module_exists('token')) {
        $form['tokens'] = array(
          '#type' => 'fieldset',
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#title' => t('Placeholder tokens'),
          '#description' => t("The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."),
        );
        $form['tokens']['help'] = array(
          '#value' => theme('token_help', 'node'),
        );
        $form['enable_tokens'] = array(
          '#type' => 'checkbox',
          '#title' => t('Allow user-entered tokens'),
          '#default_value' => isset($field['enable_tokens']) ? $field['enable_tokens'] : 1,
          '#description' => t('Checking will allow users to enter tokens in URLs and Titles on the node edit form. This does not affect the field settings on this page.'),
        );
      }
      $form['display'] = array(
        '#tree' => TRUE,
      );
      $form['attributes'] = array(
        '#tree' => TRUE,
      );
      $form['attributes']['width'] = array(
        '#type' => 'textfield',
        '#title' => t('width of the iframe'),
        '#description' => t('iframes need fix width and height, only numbers are allowed.'),
        '#default_value' => empty($field['attributes']['width']) ? '100%' : $field['attributes']['width'],
        '#maxlength' => 4,
        '#size' => 4,
      );
      $form['attributes']['height'] = array(
        '#type' => 'textfield',
        '#title' => t('height of the iframe'),
        '#description' => t('iframes need fix width and height, only numbers are allowed.'),
        '#default_value' => empty($field['attributes']['height']) ? '700' : $field['attributes']['height'],
        '#maxlength' => 4,
        '#size' => 4,
      );
      $form['attributes']['frameborder'] = array(
        '#type' => 'select',
        '#title' => t('Frameborder'),
        '#options' => array(
          '0' => t('no frameborder'),
          'yes' => t('show frameborder'),
        ),
        '#default_value' => empty($field['attributes']['frameborder']) ? '0' : $field['attributes']['frameborder'],
        '#description' => t('Frameborder is the border arround the iframe. Mostly people want it silent, so the default value for frameborder is 0 = no.'),
      );
      $form['attributes']['scrolling'] = array(
        '#type' => 'select',
        '#title' => t('Scrolling'),
        '#options' => array(
          'auto' => t('Scrolling automatic'),
          'no' => t('Scrolling disabled'),
          'yes' => t('Scrolling enabled'),
        ),
        '#default_value' => empty($field['attributes']['scrolling']) ? 'auto' : $field['attributes']['scrolling'],
        '#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['attributes']['transparency'] = array(
        '#type' => 'select',
        '#title' => t('Transparency'),
        '#options' => array(
          '0' => t('no transparency'),
          'yes' => t('allow transparency'),
        ),
        '#default_value' => empty($field['attributes']['transparency']) ? '0' : $field['attributes']['transparency'],
        '#description' => t('Allow transparency per CSS in the outer iframe tag. You have to set background-color:transparent in Your IFrame too for the body tag!'),
      );
      $form['attributes']['class'] = array(
        '#type' => 'textfield',
        '#title' => t('Additional CSS Class'),
        '#description' => t('Adds this class-definition to the iframe. Multiple classes should be separated by spaces. You can use a class "autoresize" if You want height-autoresizing for iframes of the same domain.'),
        '#default_value' => empty($field['attributes']['class']) ? '' : $field['attributes']['class'],
      );
      return $form;
    case 'validate':
      if ($field['title'] == 'value' && empty($field['title_value'])) {
        form_set_error('title_value', t('A default title must be provided if the title is a static value'));
      }
      if (empty($field['attributes']['width']) || (int) $field['attributes']['width'] < 1) {
        form_set_error('width_value', t('A default width and height must be provided.'));
      }
      if (empty($field['attributes']['height']) || (int) $field['attributes']['height'] < 1) {
        form_set_error('height_value', t('A default width and height must be provided.'));
      }
      break;
    case 'save':
      return array(
        'attributes',
        'display',
        'url',
        'title',
        'title_value',
        'enable_tokens',
      );
    case 'database columns':
      return array(
        'url' => array(
          'type' => 'varchar',
          'length' => 1024,
          'not null' => FALSE,
          'sortable' => TRUE,
        ),
        'title' => array(
          'type' => 'varchar',
          'length' => 255,
          'not null' => FALSE,
          'sortable' => TRUE,
        ),
        'attributes' => array(
          'type' => 'text',
          'size' => 'medium',
          'not null' => FALSE,
        ),
      );
  }
}