You are here

toggle_editable_fields.install in Toggle Editable fields 8

Install, update and uninstall functions for the toggle_editable_fields.

File

toggle_editable_fields.install
View source
<?php

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

/**
 * Implements hook_requirements().
 */
function toggle_editable_fields_requirements($phase) {
  $requirements = [];
  $path = DRUPAL_ROOT . '/libraries/bootstrap-toggle/js/bootstrap-toggle.min.js';
  if (\Drupal::moduleHandler()
    ->moduleExists('libraries')) {
    $path = libraries_get_path('bootstrap-toggle') . '/js/bootstrap-toggle.min.js';
  }

  // Is the library found in the root libraries path.
  $library_found = file_exists($path);

  // If library is not found, then look in the current profile libraries path.
  if (!$library_found) {
    $profile_path = drupal_get_path('profile', \Drupal::installProfile());
    $profile_path .= '/libraries/bootstrap-toggle/js/bootstrap-toggle.min.js';

    // Is the library found in the current profile libraries path.
    $library_found = file_exists($profile_path);
  }
  if (!$library_found) {
    $requirements['bootstrap_toggle_library'] = [
      'title' => t('Bootstrap Toggle library missing'),
      'description' => t('Bootstrap Toggle requires the bootstrap-toggle.min.js library.
        Download it (https://github.com/minhur/bootstrap-toggle) and place it in the
        libraries folder (/libraries)'),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  return $requirements;
}

Functions