How about an iframe formatter? Easy way to add an embedded you tube video without any coding.

I've successfully modified the link module's source to do this (settings to configure the iframe formatter just includes width and height) But I cannot get my own module to add the new formatter so an upgrade won't blow away my changes. I must be missing something.

CommentFileSizeAuthor
#2 link-1651656-2-iframe-formatter.patch2.81 KBduellj

Comments

donpwinston’s picture

Here is my code that adds an iframe formatter. I haven't figured out how to add this formatter without modifying the link.module file.

/**
 * Implements hook_theme(). (modified)
 */
function link_theme() {
  return array(
    /*'link_field_settings' => array(
      'variables' => array('element' => NULL),
    ),*/
    'link_formatter_link_default' => array(
      'variables' => array('element' => NULL),
    ),
    'link_formatter_link_plain' => array(
      'variables' => array('element' => NULL),
    ),
    'link_formatter_link_title_plain' => array(
      'variables' => array('element' => NULL),
    ),
    'link_formatter_link_url' => array(
      'variables' => array('element' => NULL),
    ),
    'link_formatter_link_short' => array(
      'variables' => array('element' => NULL),
    ),
    'link_formatter_link_label' => array(
      'variables' => array('element' => NULL),
    ),
    'link_formatter_link_separate' => array(
      'variables' => array('element' => NULL),
    ),
    'link_formatter_link_iframe' => array(
      'variables' => array('element' => NULL),
    ),
    'link_field' => array(
      'render element' => 'element',
    ),
  );
}

/**
 * Implementation of hook_field_formatter_info(). (modified)
 */
function link_field_formatter_info() {
  return array(
    'link_default' => array(
      'label' => t('Title, as link (default)'),
      'field types' => array('link_field'),
      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
    ),
    'link_title_plain' => array(
      'label' => t('Title, as plain text'),
      'field types' => array('link_field'),
      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
    ),
    'link_url' => array(
      'label' => t('URL, as link'),
      'field types' => array('link_field'),
      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
    ),
    'link_plain' => array(
      'label' => t('URL, as plain text'),
      'field types' => array('link_field'),
      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
    ),
    'link_short' => array(
      'label' => t('Short, as link with title "Link"'),
      'field types' => array('link_field'),
      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
    ),
    'link_label' => array(
      'label' => t('Label, as link with label as title'),
      'field types' => array('link_field'),
      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
    ),
    'link_separate' => array(
      'label' => t('Separate title and URL'),
      'field types' => array('link_field'),
      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
    ),
    'link_iframe' => array(
      'label' => t('Embedded iframe'),
      'field types' => array('link_field'),
      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
      'settings' => array(
        'width' => '400',
        'height' => '300',
      ),
    ),
  );
}

/**
 * Implements hook_field_formatter_settings_form(). (new)
 */
function link_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $element = array();
  if ($display['type'] == 'link_iframe') {
    $element['width'] = array(
      '#title' => t('Width'),
      '#type' => 'textfield',
      '#size' => 10,
      '#default_value' => $settings['width'],
      '#element_validate' => array('element_validate_integer_positive'),
      '#required' => TRUE,
    );
    $element['height'] = array(
      '#title' => t('Height'),
      '#type' => 'textfield',
      '#size' => 10,
      '#default_value' => $settings['height'],
      '#element_validate' => array('element_validate_integer_positive'),
      '#required' => TRUE,
    );
  }
  return $element;
}

/**
 * Implements hook_field_formatter_settings_summary(). (new)
 */
function link_field_formatter_settings_summary($field, $instance, $view_mode) {
  $display = $instance['display'][$view_mode];
  $settings = $display['settings'];
  $summary = $display['type'] == 'link_iframe' ?
  	'width='. $settings['width'] .' height='. $settings['height'] : '';
  return $summary;
}

/**
 * Theme function for 'iframe' link field formatter. (new)
 */
function theme_link_formatter_link_iframe($vars) {
	//see($vars['field']['display']);
	return '<iframe width="'. $vars['field']['display']['default']['settings']['width'] .' "height="' .
		$vars['field']['display']['default']['settings']['height'] .'" src="'. $vars['element']['url']
		.'" frameborder="0" allowfullscreen></iframe><br />'. $vars['element']['title'];
}
donpwinston’s picture

Issue summary: View changes

Just talk about problem.

duellj’s picture

Status: Active » Needs review
StatusFileSize
new2.81 KB

Here's a patch that implements everything from #1, with some cleanup to the theme function.

duellj’s picture

Issue summary: View changes

Settings just includes width and height

manuel.adan’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)

Module link_iframe_formatter already makes that.