You are here

aos.install in Animate On Scroll 8

Same filename and directory in other branches
  1. 7 aos.install

Library requirements for AOS.

File

aos.install
View source
<?php

/**
 * @file
 * Library requirements for AOS.
 */

/**
 * Implements hook_install().
 */
function aos_install() {

  // Check for AOS Library.
  $library = \Drupal::service('library.discovery')
    ->getLibraryByName('aos', 'aos_lib');
  $library_exists = file_exists(DRUPAL_ROOT . '/' . $library['css'][0]['data']);
  if (!$library_exists) {
    $download_url = 'https://github.com/michalsnik/aos/archive/master.zip';
    $message = t('Animate On Scroll module requires the AOS library. <a href=":aos_lib_link">Download AOS library</a> and unzip into /libraries/aos.', [
      ':aos_lib_link' => $download_url,
    ]);
    $messenger = \Drupal::messenger();
    $messenger
      ->addMessage($message, 'warning');
  }
}

/**
 * Implements hook_requirements().
 */
function aos_requirements($phase) {

  // Verify AOS is enabled.
  if ($phase == 'runtime') {
    $library = \Drupal::service('library.discovery')
      ->getLibraryByName('aos', 'aos_lib');
    $library_exists = file_exists(DRUPAL_ROOT . '/' . $library['css'][0]['data']);
    return [
      'aos_library_downloaded' => [
        'title' => t('AOS library'),
        'value' => $library_exists ? t('Installed') : t('Not installed'),
        'description' => $library_exists ? '' : t('The AOS library needs to be <a href="@url">downloaded</a> and extracted into the /libraries/aos folder in your Drupal installation directory.', [
          '@url' => 'https://github.com/michalsnik/aos/archive/master.zip',
        ]),
        'severity' => $library_exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
      ],
    ];
  }
}

Functions

Namesort descending Description
aos_install Implements hook_install().
aos_requirements Implements hook_requirements().