You are here

twitter_feed.install in Twitter_Feed 8

Installation actions for Twitter Feed.

File

twitter_feed.install
View source
<?php

/**
 * @file
 * Installation actions for Twitter Feed.
 */

/**
 * Implements hook_uninstall().
 *
 * Deletes all content and configuration installed by this module.
 */
function twitter_feed_uninstall() {

  // Delete all of the configuration installed by this module.
  $dir = drupal_get_path('module', 'twitter_feed') . '/config/install';
  $files = \Drupal::service('file_system')
    ->scanDirectory($dir, '/.*/');
  foreach ($files as $file) {
    \Drupal::configFactory()
      ->getEditable($file->name)
      ->delete();
  }
  \Drupal::logger('twitter_feed')
    ->info(t('Deleted Twitter Feed configuration'), []);
}

/**
 * Implements hook_requirements().
 */
function twitter_feed_requirements($phase) {
  $requirements = [];

  // Check to see if the Timeago library is available.
  if ($phase == 'runtime') {
    $installed = FALSE;
    $requirements['timeago'] = [
      'title' => 'Timeago',
    ];
    if (function_exists('libraries_get_path')) {
      $version = 1.5;
      $requirements['timeago']['description'] = t('Version %version installed.', [
        '%version' => $version,
      ]);
      $requirements['timeago']['severity'] = REQUIREMENT_OK;

      // @todo have the version automatically detected
      $requirements['timeago']['value'] = $version;
      $path = libraries_get_path('timeago');
      $installed = file_exists($path . '/jquery.timeago.js');
    }

    // Check the results of the test.
    if (!$installed) {
      $requirements['timeago']['description'] = t('Timeago library not found. Please consult the README.txt for installation instructions.');
      $requirements['timeago']['severity'] = REQUIREMENT_WARNING;
      $requirements['timeago']['value'] = t('Timeago library not found.');
    }
  }
  return $requirements;
}

Functions