You are here

total_control.module in Total Control Admin Dashboard 8.2

File

total_control.module
View source
<?php

/**
 * @file
 * Contains total_control.module.
 */
use Symfony\Component\Yaml\Yaml;

/**
 * Implements hook_element_info_alter().
 */
function total_control_element_info_alter(array &$types) {

  // Attach our extra CSS for toolbar icons.
  if (isset($types['toolbar'])) {
    $types['toolbar']['#attached']['library'][] = 'total_control/tc';
  }
}

/**
 * Implements hook_modules_installed().
 */
function total_control_modules_installed($modules) {

  // When we enable the Comment module we load the Drupal standard configs.
  // And the Total Control Comments view.
  if (in_array('comment', $modules)) {
    $comment_managed_optional_path = Drupal::service('module_handler')
      ->getModule('total_control')
      ->getPath() . '/config/managed/comment';

    // Drupal core standard profile configs for comment.
    $comment_managed_optional_configs = [
      'comment.type.comment',
      'field.field.comment.comment.comment_body',
      'rdf.mapping.comment.comment',
      'core.entity_form_display.comment.comment.default',
      'core.entity_view_display.comment.comment.default',
      'field.storage.node.comment',
      'views.view.control_comments',
    ];
    foreach ($comment_managed_optional_configs as $config_name) {
      $config_path = $comment_managed_optional_path . '/' . $config_name . '.yml';
      $config_content = file_get_contents($config_path);
      $config_data = (array) Yaml::parse($config_content);
      $config_factory = \Drupal::configFactory()
        ->getEditable($config_name);
      $config_factory
        ->setData($config_data)
        ->save(TRUE);
    }
  }

  // When we enable the Taxonomy module then we add the Total Control Term view.
  if (in_array('taxonomy', $modules)) {
    $taxonomy_managed_optional_path = Drupal::service('module_handler')
      ->getModule('total_control')
      ->getPath() . '/config/managed/taxonomy';
    $taxonomy_managed_optional_configs = [
      'views.view.control_terms',
    ];
    foreach ($taxonomy_managed_optional_configs as $config_name) {
      $config_path = $taxonomy_managed_optional_path . '/' . $config_name . '.yml';
      $config_content = file_get_contents($config_path);
      $config_data = (array) Yaml::parse($config_content);
      $config_factory = \Drupal::configFactory()
        ->getEditable($config_name);
      $config_factory
        ->setData($config_data)
        ->save(TRUE);
    }
  }
}