<?php

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

/**
 * Implements hook_requirements().
 */
function devel_requirements($phase) {
  $requirements = [];

  if ($phase == 'runtime') {
    // To understand the reasons why this message is marked as info see
    // https://www.drupal.org/node/2834400.
    $requirements['devel'] = [
      'title' => t('Devel module enabled'),
      'description' => t('The Devel module provides access to internal debugging information; therefore it\'s recommended to disable this module on sites in production.'),
      'severity' => REQUIREMENT_INFO,
    ];
  }

  return $requirements;
}

/**
 * Set the default devel dumper plugin.
 */
function devel_update_8001() {
  $kint_enabled = \Drupal::moduleHandler()->moduleExists('kint');

  $default_dumper = $kint_enabled ? 'kint' : 'default';

  // Set the default dumper plugin to kint if kint module is available.
  \Drupal::configFactory()->getEditable('devel.settings')
    ->set('devel_dumper', $default_dumper)
    ->save(TRUE);
}

/**
 * Add enforced dependencies to system.menu.devel
 */
function devel_update_8002() {
  $config = \Drupal::configFactory()->getEditable('system.menu.devel');
  $dependencies = $config->get('dependencies');
  $dependencies['enforced']['module'][] = 'devel';
  $config->set('dependencies', $dependencies)->save(TRUE);
}
