You are here

iframe.module in Iframe 8

Same filename and directory in other branches
  1. 8.2 iframe.module
  2. 6 iframe.module
  3. 7 iframe.module

Defines an iframe field with all attributes.

File

iframe.module
View source
<?php

/**
 * @file
 * Defines an iframe field with all attributes.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
if (!defined('IFRAME_DEBUG_LEVEL')) {
  define('IFRAME_DEBUG_LEVEL', 0);
}

/**
 * Debug the iframe module.
 *
 * Function "dpr" is from devel-module, we will use it if exists.
 */
function iframe_debug($level, $func = 'iframe', $debugvar = NULL) {
  if ($level <= IFRAME_DEBUG_LEVEL) {
    try {
      $develdumper = \Drupal::service('devel.dumper', false);
    } catch (Exception $exception) {
      $develdumper = '';
    }
    if (isset($develdumper) && is_object($develdumper)) {
      $develdumper
        ->dumpOrExport($debugvar, $func, NULL, 'drupal_variable');
    }
    else {
      if (is_object($debugvar)) {
        $debugvar = [
          get_class($debugvar),
          get_class_methods($debugvar),
        ];
      }
      error_log('ID: ' . $level . ' ' . $func);
      \Drupal::messenger()
        ->addMessage('[iframe(' . $level . ')] ' . $func . ' ' . print_r($debugvar, TRUE), 'warning');
    }
  }
}

/**
 * Implements hook_help().
 */
function iframe_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.iframe':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The Iframe module allows you to create fields that contain iframe URLs and iframe title text. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":iframe_documentation">online documentation for the Link module</a>.', [
        ':field' => Url::fromRoute('help.page', [
          'name' => 'field',
        ])
          ->toString(),
        ':field_ui' => \Drupal::moduleHandler()
          ->moduleExists('field_ui') ? Url::fromRoute('help.page', [
          'name' => 'field_ui',
        ])
          ->toString() : '#',
        ':iframe_documentation' => 'https://www.drupal.org/documentation/modules/iframe',
      ]) . '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Managing and displaying iframe fields') . '</dt>';
      $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the iframe field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [
        ':field_ui' => \Drupal::moduleHandler()
          ->moduleExists('field_ui') ? Url::fromRoute('help.page', [
          'name' => 'field_ui',
        ])
          ->toString() : '#',
      ]) . '</dd>';
      $output .= '<dt>' . t('Adding attributes to iframes') . '</dt>';
      $output .= '<dd>' . t('You can add attributes to iframes, by changing the <em>Format settings</em> in the <em>Manage display</em> page. Further definable are attributes for styling the iframe, like: URL, width, height, title, class, frameborder, scrolling and transparency.') . '</dd>';
      $output .= '<dt>' . t('Validating URLs') . '</dt>';
      $output .= '<dd>' . t('All URLs are validated after a iframe field is filled in. They can include anchors or query strings.') . '</dd>';
      $output .= '</dl>';
      return $output;
  }
}

/**
 * Implements hook_theme().
 */
function BRANCH81_iframe_theme() {
  return [
    'iframe' => [
      'variables' => [
        'src' => '',
        'attributes' => [],
        'text' => '',
        'style' => '',
      ],
    ],
  ];
}

Functions

Namesort descending Description
BRANCH81_iframe_theme Implements hook_theme().
iframe_debug Debug the iframe module.
iframe_help Implements hook_help().