You are here

bynder.install in Bynder 8

Install, uninstall and update hooks for Bynder module.

File

bynder.install
View source
<?php

/**
 * @file
 * Install, uninstall and update hooks for Bynder module.
 */

/**
 * Implements hook_requirements().
 */
function bynder_requirements($phase) {
  $requirements = [];
  $imagesloaded_path = DRUPAL_ROOT . '/libraries/imagesloaded/imagesloaded.pkgd.min.js';
  $masonry_path = DRUPAL_ROOT . '/libraries/masonry/dist/masonry.pkgd.min.js';
  if (!file_exists($imagesloaded_path)) {
    $requirements['imagesloaded'] = array(
      'title' => t('ImagesLoaded library missing'),
      'description' => t('Bynder requires the imagesLoaded library. Download the newest release from https://github.com/desandro/imagesloaded releases and place it in /libraries'),
      'severity' => REQUIREMENT_ERROR,
    );
  }
  if (!file_exists($masonry_path)) {
    $requirements['masonry'] = array(
      'title' => t('Masonry library missing'),
      'description' => t('Bynder requires the Masonry library. Download the newest release from https://github.com/desandro/masonry/releases and place it in /libraries'),
      'severity' => REQUIREMENT_ERROR,
    );
  }
  return $requirements;
}

/**
 * Implements hook_install().
 */
function bynder_install() {
  $source = drupal_get_path('module', 'bynder') . '/images/icons';
  $destination = \Drupal::config('media_entity.settings')
    ->get('icon_base');
  media_entity_copy_icons($source, $destination);
}

/**
 * Install Bynder metaproperty schema.
 */
function bynder_update_8001() {

  // Removed so it won't run on sites that didn't run it yet.
}

/**
 * Remove unecessary database table.
 */
function bynder_update_8002() {
  if (db_table_exists('bynder_metaproperty_information')) {
    db_drop_table('bynder_metaproperty_information');
  }
}

/**
 * Update module's configuration.
 */
function bynder_update_8003() {
  \Drupal::configFactory()
    ->getEditable('bynder.settings')
    ->set('cache_lifetime', 86400)
    ->clear('derivatives')
    ->save();
}

/**
 * Update cached information.
 */
function bynder_update_8004() {
  \Drupal::service('bynder_api')
    ->updateCachedData();
}

/**
 * Set default timeout for API requests.
 */
function bynder_update_8005() {
  \Drupal::configFactory()
    ->getEditable('bynder.settings')
    ->set('timeout', 10)
    ->save();
}

Functions

Namesort descending Description
bynder_install Implements hook_install().
bynder_requirements Implements hook_requirements().
bynder_update_8001 Install Bynder metaproperty schema.
bynder_update_8002 Remove unecessary database table.
bynder_update_8003 Update module's configuration.
bynder_update_8004 Update cached information.
bynder_update_8005 Set default timeout for API requests.