You are here

entity_embed.install in Entity Embed 7

Install, update and uninstall functions for the entity_embed module.

File

entity_embed.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the entity_embed module.
 */

/**
 * Implements hook_requirements().
 */
function entity_embed_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {

    // Check if the site is running >= jQuery 1.7.
    if (($library = drupal_get_library('system', 'jquery')) && version_compare($library['version'], 1.7, '>=')) {
      $requirements['entity_embed_jquery'] = array(
        'title' => t('Entity Embed jQuery version'),
        'value' => t('jQuery @version', array(
          '@version' => $library['version'],
        )),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $destination = drupal_get_destination();
      $requirements['entity_embed_jquery'] = array(
        'title' => t('Entity Embed jQuery version'),
        'value' => t('jQuery @version', array(
          '@version' => $library['version'],
        )),
        'description' => t('Entity Embed requires jQuery 1.7 or greater. Configure <a href="@jquery_update">jQuery Update</a>.', array(
          '@jquery_update' => url('admin/config/development/jquery_update', array(
            'query' => $destination,
          )),
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }

    // Check if the site is running >= CKEditor 4.3.
    if (($version = ckeditor_get_version()) && version_compare($version, 4.3, '>=')) {
      $requirements['entity_embed_ckeditor'] = array(
        'title' => t('Entity Embed CKEditor version'),
        'value' => t('CKEditor @version', array(
          '@version' => $version,
        )),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $requirements['entity_embed_ckeditor'] = array(
        'title' => t('Entity Embed CKEditor version'),
        'value' => t('CKEditor @version', array(
          '@version' => $version,
        )),
        'description' => t('Entity Embed requires CKEditor 4.3 or greater. Download the latest version of <a href="@ckeditor">CKEditor</a>.', array(
          '@ckeditor' => 'http://ckeditor.com/download',
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    $ckeditor_path = ckeditor_path('local');

    // CKEditor may either be installed locally or included via a CDN.
    if ($ckeditor_path != '<URL>') {
      $editor_path = _ckeditor_script_path();
      $editor_path = strtr($editor_path, array(
        "%b" => ckeditor_base_path('local'),
        "%m" => ckeditor_module_path('local'),
        "%l" => ckeditor_library_path('local'),
      ));
      $lineutils_path = $editor_path . '/plugins/lineutils';

      // Check if the CKEditor Line Utilities plugin is available.
      if (file_exists($lineutils_path)) {
        $requirements['entity_embed_lineutils'] = array(
          'title' => t('Entity Embed CKEditor Line Utilities plugin'),
          'value' => t('Line Utilities plugin found at <code>@path</code>', array(
            '@path' => $lineutils_path,
          )),
          'severity' => REQUIREMENT_OK,
        );
      }
      else {
        $requirements['entity_embed_lineutils'] = array(
          'title' => t('Entity Embed CKEditor Line Utilities plugin'),
          'value' => t('Widget plugin not found at <code>@path</code>', array(
            '@path' => $lineutils_path,
          )),
          'description' => t('Entity Embed requires the CKEditor Line Utilities plugin. Download the latest version of the <a href="@lineutils">Line Utilities</a> plugin.', array(
            '@lineutils' => 'http://ckeditor.com/addon/lineutils',
          )),
          'severity' => REQUIREMENT_ERROR,
        );
      }
      $widget_path = $editor_path . '/plugins/widget';

      // Check if the CKEditor Widget plugin is available.
      if (file_exists($widget_path)) {
        $requirements['entity_embed_widget'] = array(
          'title' => t('Entity Embed CKEditor Widget plugin'),
          'value' => t('Widget plugin found at <code>@path</code>', array(
            '@path' => $widget_path,
          )),
          'severity' => REQUIREMENT_OK,
        );
      }
      else {
        $requirements['entity_embed_widget'] = array(
          'title' => t('Entity Embed CKEditor Widget plugin'),
          'value' => t('Widget plugin not found at <code>@path</code>', array(
            '@path' => $widget_path,
          )),
          'description' => t('Entity Embed requires the CKEditor Widget API provided by the Widget plugin. Download the latest version of the <a href="@widget">Widget</a> plugin.', array(
            '@widget' => 'http://ckeditor.com/addon/widget',
          )),
          'severity' => REQUIREMENT_ERROR,
        );
      }
    }
    else {
      $editor_url = ckeditor_path('url');

      // The CKEditor Line Utilities and Widget plugins are included with the
      // standard-all and full-all distributions.
      if (preg_match("/\\/(standard|full)-all/", $editor_url)) {
        $requirements['entity_embed_lineutils'] = array(
          'title' => t('Entity Embed CKEditor Line Utilities plugin'),
          'value' => t('Line Utilities plugin included with the current CKEditor CDN distribution.'),
          'severity' => REQUIREMENT_OK,
        );
        $requirements['entity_embed_widget'] = array(
          'title' => t('Entity Embed CKEditor Widget plugin'),
          'value' => t('Widget plugin included with the current CKEditor CDN distribution.'),
          'severity' => REQUIREMENT_OK,
        );
      }
      else {
        $requirements['entity_embed_lineutils'] = array(
          'title' => t('Entity Embed CKEditor Line Utilities plugin'),
          'value' => t('Line Utilities plugin not included with the current CKEditor CDN distribution.'),
          'description' => t('Entity Embed requires the CKEditor Line Utilities plugin. You must use either the standard-all or full-all <a href="@distributions">CKEditor CDN distributions</a>.', array(
            '@distributions' => 'https://cdn.ckeditor.com/#url-structure',
          )),
          'severity' => REQUIREMENT_ERROR,
        );
        $requirements['entity_embed_widget'] = array(
          'title' => t('Entity Embed CKEditor Widget plugin'),
          'value' => t('Widget plugin not included with the current CKEditor CDN distribution.'),
          'description' => t('Entity Embed requires the CKEditor Widget API provided by the Widget plugin. You must use either the standard-all or full-all <a href="@distributions">CKEditor CDN distributions</a>.', array(
            '@distributions' => 'https://cdn.ckeditor.com/#url-structure',
          )),
          'severity' => REQUIREMENT_ERROR,
        );
      }
    }
  }
  return $requirements;
}

/**
 * Implements hook_schema().
 */
function entity_embed_schema() {
  $schema['entity_embed'] = array(
    'export' => array(
      'key' => 'name',
      'key name' => 'Name',
      'primary key' => 'cid',
      'identifier' => 'configuration',
      // Exports will be defined as $configuration.
      'default hook' => 'default_entity_embed_configuration',
      // Function hook name.
      'create callback' => 'entity_embed_embed_button_new',
      'load callback' => 'entity_embed_embed_button_load',
      'load multiple callback' => 'entity_embed_embed_button_load_multiple',
      'load all callback' => 'entity_embed_embed_button_load_all',
      'save callback' => 'entity_embed_embed_button_save',
      'delete callback' => 'entity_embed_embed_button_delete',
      'cache defaults' => TRUE,
      'default cache bin' => 'cache_entity_embed',
      'api' => array(
        'owner' => 'entity_embed',
        'api' => 'default_entity_embed_configurations',
        // Base name for api include files.
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'description' => 'Stores entity embed button configurations.',
    'fields' => array(
      'cid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
        'no export' => TRUE,
      ),
      'admin_title' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Configuration human readable title.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Configuration machine name.',
      ),
      'button_label' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Button label.',
      ),
      'entity_type' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Entity type.',
      ),
      'entity_type_bundles' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
        'serialize' => TRUE,
        'object default' => array(),
        'description' => 'Entity type bundles.',
      ),
      'button_icon_fid' => array(
        'description' => 'The {file_managed}.fid of the image representing the button.',
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
      ),
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
    'primary key' => array(
      'cid',
    ),
  );
  $schema['cache_entity_embed'] = drupal_get_schema_unprocessed('system', 'cache');
  $schema['cache_entity_embed']['description'] = 'Cache table for the Entity Embed module to store embed button configurations.';
  return $schema;
}

/**
 * Add support for restricting embedding to specific entity bundles.
 */
function entity_embed_update_7100() {

  // Add new columns to {entity_embed}.
  db_add_field('entity_embed', 'entity_type_bundles', array(
    'type' => 'text',
    'size' => 'big',
    'not null' => TRUE,
    'serialize' => TRUE,
    'object default' => array(),
    'description' => 'Entity type bundles.',
  ));

  // Clear the cache_entity_embed cache.
  cache_clear_all(NULL, 'cache_entity_embed');
}

Functions

Namesort descending Description
entity_embed_requirements Implements hook_requirements().
entity_embed_schema Implements hook_schema().
entity_embed_update_7100 Add support for restricting embedding to specific entity bundles.