You are here

function iframe_field_widget_form in Iframe 7

Implements hook_field_widget_form(). depends on the widget-type Field XYZ sub-menu "Edit" (used in the middle for "default" values for each individual instance-item, prefilled, with setting from iframe_field_info->instance_settings) (Step 3)

File

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

Code

function iframe_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  iframe_debug(2, 'iframe_field_widget_form', $form);
  $base = $element;
  $widget = $instance['widget'];

  #$settings = $widget['settings']; // size=255
  $settings = $instance['settings'];

  // for defaults
  // description of widget (help-text)
  switch ($instance['widget']['type']) {
    case 'iframe_widget_urlwidthheight':
      $element['#description'] = t('Set your iframe *URL* and the *width* and *height*.');
      break;
    case 'iframe_widget_urlheight':
      $element['#description'] = t('Set your iframe *URL* and the *height*.');
      break;
    case 'iframe_widget_url':
    default:
      $element['#description'] = t('Set your iframe *URL*.');
      break;
  }
  switch ($instance['widget']['type']) {
    case 'iframe_widget_urlwidthheight':
      $fwidth = isset($items[$delta]) && isset($items[$delta]['width']) ? $items[$delta]['width'] : (!empty($settings['width']) ? $settings['width'] : NULL);
      $element['width'] = array(
        '#type' => 'textfield',
        '#title' => t('width'),
        '#default_value' => $fwidth,
        '#size' => 4,
        '#maxlength' => 4,
        '#weight' => 4,
        '#delta' => $delta,
      );

    // no "break" intentionally, fall through
    case 'iframe_widget_urlheight':
      $fheight = isset($items[$delta]) && isset($items[$delta]['height']) ? $items[$delta]['height'] : (!empty($settings['height']) ? $settings['height'] : NULL);
      $element['height'] = array(
        '#type' => 'textfield',
        '#title' => t('height'),
        '#default_value' => $fheight,
        '#size' => 4,
        '#maxlength' => 4,
        '#weight' => 5,
        '#delta' => $delta,
        '#element_validate' => array(
          'element_validate_integer_positive',
        ),
      );

    // no "break" intentionally, fall through
    case 'iframe_widget_url':
    default:

      //
      break;
  }
  $title = isset($items[$delta]) && isset($items[$delta]['title']) ? $items[$delta]['title'] : NULL;
  $element['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Iframe Title'),
    '#placeholder' => '',
    '#default_value' => $title,
    '#size' => 80,
    '#maxlength' => 1024,
    '#weight' => 2,
    '#delta' => $delta,
  );
  $furl = isset($items[$delta]) && isset($items[$delta]['url']) ? $items[$delta]['url'] : NULL;
  $element['url'] = array(
    '#type' => 'textfield',
    '#title' => t('Iframe URL'),
    '#placeholder' => 'http://',
    '#default_value' => $furl,
    '#size' => 80,
    '#maxlength' => 1024,
    '#weight' => 1,
    '#delta' => $delta,
    '#element_validate' => array(
      'iframe_validate_url',
    ),
  );
  $fclass = isset($items[$delta]) && isset($items[$delta]['class']) ? $items[$delta]['class'] : NULL;
  $expose_class = isset($settings['expose_class']) ? $settings['expose_class'] : 1;
  if ($expose_class) {
    $element['class'] = array(
      '#type' => 'textfield',
      '#title' => t('Additional CSS Class'),
      '#default_value' => $fclass,
      '#description' => t('Multiple classes should be separated by spaces.<br />You can use a class "autoresize" if You want height-autoresizing for iframes of the same domain.'),
      '#size' => 80,
      '#weight' => 5,
      '#delta' => $delta,
    );
  }

  // Display the list of available placeholders if token module is installed.
  $tokensupport = !empty($settings['tokensupport']) ? (int) $settings['tokensupport'] : 0;
  if ($tokensupport > 0) {
    if (module_exists('token')) {
      $element['token_tree'] = array(
        '#theme' => 'token_tree_link',
        '#token_types' => array(
          'node',
          'user',
        ),
        '#weight' => 3,
      );
      $element['url']['#description'] = (!empty($element['url']['#description']) ? $element['url']['#description'] . " " : "") . t('Field does support tokens.');
      $element['title']['#description'] = (!empty($element['title']['#description']) ? $element['title']['#description'] . " " : "") . t('Field does support tokens.');
    }
    else {
      $element['token_tree'] = array(
        '#markup' => '<p>' . t('Enable the <a href="@drupal-token">Token module</a> to view the available token browser.', array(
          '@drupal-token' => 'http://drupal.org/project/token',
        )) . '</p>',
      );
    }
  }
  iframe_debug(2, 'iframe_field_widget_form', array(
    'settings' => $settings,
    'instance-settings' => $instance['settings'],
  ));
  return $element;
}