You are here

wingsuit_companion.install in Gin Layout Builder 8.2

Provides install/uninstall for wingsuit_companion module.

File

wingsuit_companion.install
View source
<?php

/**
 * @file
 * Provides install/uninstall for wingsuit_companion module.
 */

/**
 * Install Wingsuit UI Patterns sub module.
 */
function wingsuit_companion_update_8001() {
  \Drupal::service('module_installer')
    ->install([
    'wingsuit_ui_patterns',
  ]);
  $config_factory = \Drupal::configFactory();
  $config = $config_factory
    ->get('wingsuit_companion.config');
  $dist_path = $config
    ->get('dist_path');
  $absolute_path = _wingsuit_companion_canonicalize(\Drupal::service('theme_handler')
    ->getTheme('wingsuit')
    ->getPath() . $dist_path);
  $config_factory
    ->getEditable('wingsuit_companion.config')
    ->set('dist_path', $absolute_path)
    ->save();
}

/**
 * Canonicalize relative dist folder.
 *
 * @param $path
 *   The relative dist path.
 *
 * @return string
 *   The absolute path.
 */
function _wingsuit_companion_canonicalize($path) {
  $path = explode('/', $path);
  $keys = array_keys($path, '..');
  foreach ($keys as $keypos => $key) {
    array_splice($path, $key - ($keypos * 2 + 1), 2);
  }
  $path = implode('/', $path);
  $path = str_replace('./', '', $path);
  return $path;
}

/**
 * Implements hook_install().
 *
 * Set default dist_path to "themes/custom/wingsuit/dist/app-drupal"
 */
function wingsuit_companion_install() {
  $config_factory = \Drupal::configFactory();
  $config = $config_factory
    ->getEditable('wingsuit_companion.config');
  $config
    ->set('dist_path', 'themes/custom/wingsuit/dist/app-drupal');
  $config
    ->save(TRUE);
}

Functions

Namesort descending Description
wingsuit_companion_install Implements hook_install().
wingsuit_companion_update_8001 Install Wingsuit UI Patterns sub module.
_wingsuit_companion_canonicalize Canonicalize relative dist folder.