You are here

js_injector.install in JS injector 8

js_injector.install

Install, update and uninstall functions for the js_injector module.

File

js_injector.install
View source
<?php

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

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

  // Create the js_injector directory and ensure it's writable.
  $directory = file_default_scheme() . '://js_injector';
  file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}

/**
 * Implements hook_uninstall().
 */
function js_injector_uninstall() {

  // Remove the js_injector directory and generated rules.
  file_unmanaged_delete_recursive(file_default_scheme() . '://js_injector');
}

/**
 * Migrate js_injector rules into configuration.
 *
 * @ingroup config_upgrade
 */
function js_injector_update_8000() {
  $uuid = new Uuid();
  $rules = db_select('js_injector_rule', 'r')
    ->fields('r')
    ->execute()
    ->fetchAll();
  foreach ($rules as $rule) {
    config('js_injector.rule.' . $rule->crid)
      ->set('id', $rule->crid)
      ->set('uuid', $uuid
      ->generate())
      ->set('label', $rule->name)
      ->set('weight', $rule->weight)
      ->set('langcode', LANGUAGE_NOT_SPECIFIED)
      ->save();
  }
  update_config_manifest_add('js_injector.rule', array_map(function ($rule) {
    return $rule->crid;
  }, $rules));
}

/**
 * Drop the {js_injector_rule} table.
 */
function js_injector_update_8001() {
  db_drop_table('js_injector_rule');
}

Functions

Namesort descending Description
js_injector_install Implements hook_install().
js_injector_uninstall Implements hook_uninstall().
js_injector_update_8000 Migrate js_injector rules into configuration.
js_injector_update_8001 Drop the {js_injector_rule} table.