xprofile-2.x-dev/xprofile.install

xprofile.install
<?php

use Drupal\Component\Utility\OpCodeCache;
use Drupal\Core\Site\Settings;

/**
 * Implements hook_install_tasks().
 */
function xprofile_install_tasks(&$install_state) {
  return [
    'xprofile_override_config' => [],
  ];
}

/**
 * Implements hook_install_tasks_alter().
 */
function xprofile_install_tasks_alter(&$tasks, $install_state) {
  $tasks = [
    'xprofile_change_settingsphp' => [],
    'xprofile_change_servicesyml' => [],
  ] + $tasks;
}

/**
 * Configure settings.php task.
 */
function xprofile_change_settingsphp($install_state) {
  $site_path = './' . \Drupal::service('site.path');
  $settings_path = $site_path . '/settings.php';
  $default_settings_path = './sites/default/default.settings.php';

  // Copy default.settings.php to settings.php.
  if (!drupal_verify_install_file($settings_path, FILE_EXIST) && drupal_verify_install_file($site_path, FILE_EXIST | FILE_WRITABLE, 'dir')) {
    @copy($default_settings_path, $settings_path);
  }

  // Change settings.php.
  if (drupal_verify_install_file($settings_path, FILE_EXIST | FILE_READABLE | FILE_WRITABLE)) {
    $settings = file_get_contents($settings_path);
    $settings = strtr($settings, [
      "# \$settings['file_public_path'] = 'sites/default/files';" =>
      "\$settings['file_public_path'] = \$site_path . '/files/public';",

      "# \$settings['file_private_path'] = '';" =>
      "\$settings['file_private_path'] = \$site_path . '/files/private';",

      "# \$settings['file_temp_path'] = '/tmp';" =>
      "\$settings['file_temp_path'] = \$site_path . '/files/temp';",

      "# \$settings['session_write_interval'] = 180;" =>
      "\$settings['session_write_interval'] = 600;",

      "\$settings['entity_update_backup'] = TRUE;" =>
      "\$settings['entity_update_backup'] = FALSE;",

      "# if (file_exists(\$app_root . '/' . \$site_path . '/settings.local.php')) {\n#   include \$app_root . '/' . \$site_path . '/settings.local.php';\n# }" =>
      "if (file_exists(\$local_settings_file = \"\$app_root/\$site_path/settings.local.php\")) {\n  include \$local_settings_file;\n}\n",

      "# \$settings['config_sync_directory'] = '/directory/outside/webroot';" =>
      "\$settings['config_sync_directory'] = \$site_path . '/files/config/sync';",
    ]);
    file_put_contents($settings_path, $settings);
  }

  // Copy example.settings.local.php to settings.local.php.
  $settings_local_path = $site_path . '/settings.local.php';
  @copy('sites/example.settings.local.php', $settings_local_path);

  // Change settings.local.php.
  $settings_local = file_get_contents($settings_local_path);
  $settings_local = strtr($settings_local, [
    "\$config['system.logging']['error_level'] = 'verbose';" =>
    "\$config['system.logging']['error_level'] = 'all';",

    "# \$settings['cache']['bins']['page'] = 'cache.backend.null';" =>
    "if (isset(\$_GET['no-render-cache'])) { \$settings['cache']['bins']['render'] = 'cache.backend.null'; }",
  ]);
  file_put_contents($settings_local_path, $settings_local);

  // Clear settings cache.
  $class_loader = \Drupal::service('class_loader');
  Settings::initialize(DRUPAL_ROOT, $site_path, $class_loader);
  OpCodeCache::invalidate($settings_path);
}

/**
 * Configure services.yml.
 */
function xprofile_change_servicesyml($install_state) {
  // services.yml
  $services_path = 'sites/default/services.yml';
  @copy('sites/default/default.services.yml', $services_path);
  $services = file_get_contents($services_path);
  $services = strtr($services, [
    'gc_maxlifetime: 200000' => 'gc_maxlifetime: 3000000',
    'cookie_lifetime: 2000000' => 'cookie_lifetime: 8000000',
  ]);
  file_put_contents($services_path, $services);

  // development.services.yml
  $development_services_path = 'sites/development.services.yml';
  $development_services = file_get_contents($development_services_path);
  if (strpos($development_services, 'twig.config') === FALSE) {
    $development_services_content = "" .
      "parameters:\n" .
      "  twig.config:\n" .
      "    debug: false\n" .
      "    auto_reload: true\n" .
      "  http.response.debug_cacheability_headers: false\n" .
      "services:\n" .
      "  cache.backend.null:\n" .
      "    class: Drupal\Core\Cache\NullBackendFactory\n";
    file_put_contents($development_services_path, $development_services_content);
  }
}

/**
 * Override config.
 */
function xprofile_override_config() {
  $config_factory = \Drupal::configFactory();

  $config = [
    'system.file' => [
      'path.temporary' => 'sites/default/files/temp',
      'temporary_maximum_age' => 86400,
    ],
    'file.settings' => [
      'make_unused_managed_files_temporary' => TRUE,
    ],
    'pathauto.settings' => [
      'enabled_entity_types' => [],
      'reduce_ascii' => TRUE,
      'ignore_words' => '',
    ],
    'contact.settings' => [
      'user_default_enabled' => FALSE,
    ],
    'views.settings' => [
      'ui.show.advanced_column' => TRUE,
      'ui.show.master_display' => TRUE,
      'ui.show.performance_statistics' => TRUE,
      'ui.show.sql_query.enabled' => TRUE,
      'ui.show.display_embed' => TRUE,
    ],
    'views.view.block_content' => [
      'display.default.display_options.filters' => [],
    ],
    'views.view.watchdog' => [
      'display.default.display_options.pager.type' => 'full',
    ],
    'views.view.content_recent' => [
      'status' => FALSE,
    ],
    'views.view.frontpage' => [
      'status' => FALSE,
    ],
    'views.view.taxonomy_term' => [
      'status' => FALSE,
    ],
    'views.view.who_s_new' => [
      'status' => FALSE,
    ],
    'views.view.who_s_online' => [
      'status' => FALSE,
    ],
    'devel.settings' => [
      'devel_dumper' => 'kint',
    ],
    'update.settings' => [
      'check.interval_days' => 7,
      'notification.threshold' => 'security',
      'emails' => [],
    ],
    'node.settings' => [
      'use_admin_theme' => TRUE,
    ],
    'captcha.settings' => [
      'add_captcha_description' => FALSE,
    ],
    'captcha.captcha_point.user_pass' => [
      'status' => TRUE,
    ],
    'captcha.captcha_point.user_register_form' => [
      'status' => TRUE,
    ],
    'backup_migrate.backup_migrate_schedule.daily_schedule' => [
      'enabled' => TRUE,
      'keep' => 30,
      'period' => 86400,
    ],
  ];

  foreach ($config as $config_group => $config_items) {
    foreach ($config_items as $config_key => $config_value) {
      $config_factory->getEditable($config_group)->set($config_key, $config_value)->save(TRUE);
    }
  }

  $delete_config = [
    'image.style.large',
    'image.style.medium',
    'image.style.thumbnail',
    'core.date_format.long',
    'core.date_format.medium',
  ];

  foreach ($delete_config as $name) {
    $config_factory->getEditable($name)->delete();
  }
}

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

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc