You are here

function iframe_process in Iframe 6

Process the iframe type element before displaying the field.

Build the form element. When creating a form using FAPI #process, note that $element['#value'] is already set.

The $fields array is in $form['#field_info'][$element['#field_name']].

1 string reference to 'iframe_process'
iframe_elements in ./iframe.module
Implementation of hook_elements().

File

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

Code

function iframe_process($element, $edit, $form_state, $form) {
  dmsg(3, 'func iframe_process');
  $field = $form['#field_info'][$element['#field_name']];
  $delta = $element['#delta'];

  // load attributes by node
  _iframe_load($element['#value']);
  dmsg(4, 'func iframe_process after _iframe_load');
  $element['url'] = array(
    '#type' => 'textfield',
    '#maxlength' => '1024',
    '#title' => t('URL'),
    '#description' => $element['#description'],
    '#required' => $delta == 0 && $field['url'] !== 'optional' ? $element['#required'] : FALSE,
    '#default_value' => isset($element['#value']['url']) ? $element['#value']['url'] : NULL,
  );
  if ($field['title'] != 'none' && $field['title'] != 'value') {
    $element['title'] = array(
      '#type' => 'textfield',
      '#maxlength' => '255',
      '#title' => t('Title'),
      '#required' => $delta == 0 && $field['title'] == 'required' ? $field['required'] : FALSE,
      '#default_value' => isset($element['#value']['title']) ? $element['#value']['title'] : NULL,
    );
  }
  $element['attributes']['width'] = array(
    '#type' => 'textfield',
    '#maxlength' => '4',
    '#size' => '4',
    '#title' => t('Width'),
    '#required' => $delta == 0 && $field['width'] == 'required' ? $field['required'] : FALSE,
    '#default_value' => !empty($element['#value']['attributes']['width']) ? $element['#value']['attributes']['width'] : $field['attributes']['width'],
  );
  $element['attributes']['height'] = array(
    '#type' => 'textfield',
    '#maxlength' => '4',
    '#size' => '4',
    '#title' => t('Height'),
    '#required' => $delta == 0 && $field['height'] == 'required' ? $field['required'] : FALSE,
    '#default_value' => !empty($element['#value']['attributes']['height']) ? $element['#value']['attributes']['height'] : $field['attributes']['height'],
  );
  $element['attributes']['frameborder'] = array(
    '#type' => 'select',
    '#title' => t('Frameborder'),
    '#options' => array(
      '0' => t('no frameborder'),
      'yes' => t('show frameborder'),
    ),
    '#description' => t('Frameborder is the border arround the iframe. Mostly people want it silent, so the default value for frameborder is 0.'),
    '#required' => $delta == 0 && $field['frameborder'] == 'required' ? $field['required'] : FALSE,
    '#default_value' => !empty($element['#value']['attributes']['frameborder']) ? $element['#value']['attributes']['frameborder'] : $field['attributes']['frameborder'],
  );
  $element['attributes']['scrolling'] = array(
    '#type' => 'select',
    '#title' => t('Scrolling'),
    '#options' => array(
      'auto' => t('Scrolling automatic'),
      'no' => t('Scrolling disabled'),
      'yes' => t('Scrolling enabled'),
    ),
    '#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.'),
    '#required' => $delta == 0 && $field['scrolling'] == 'required' ? $field['required'] : FALSE,
    '#default_value' => !empty($element['#value']['attributes']['scrolling']) ? $element['#value']['attributes']['scrolling'] : $field['attributes']['scrolling'],
  );
  $element['attributes']['transparency'] = array(
    '#type' => 'select',
    '#title' => t('Transparency'),
    '#options' => array(
      '0' => t('no transparency'),
      'yes' => t('allow 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!'),
    '#required' => $delta == 0 && $field['transparency'] == 'required' ? $field['required'] : FALSE,
    '#default_value' => !empty($element['#value']['attributes']['transparency']) ? $element['#value']['attributes']['transparency'] : $field['attributes']['transparency'],
  );
  $element['attributes']['class'] = array(
    '#type' => 'textfield',
    '#title' => t('Additional CSS Class'),
    '#description' => t('When output, this iframe will have this class attribute. Multiple classes should be separated by spaces. In future versions You can use a class "autoresize" if You want autoresizing the height for iframes which originates from the same domain.'),
    '#required' => $delta == 0 && $field['class'] == 'required' ? $field['required'] : FALSE,
    '#default_value' => !empty($element['#value']['attributes']['class']) ? $element['#value']['attributes']['class'] : $field['attributes']['class'],
  );
  return $element;
}