quick_start-8.x-1.0-beta10/quick_start.install
quick_start.install
<?php
/**
* @file
* Install, update and uninstall functions for the profilename install profile.
*/
use Symfony\Component\Yaml\Yaml;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Drupal\shortcut\Entity\Shortcut;
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function quick_start_install() {
// Set front page to "node".
\Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node')->save(TRUE);
// Assign user 1 the "administrator" role.
$user = User::load(1);
$user->roles[] = 'administrator';
$user->save();
// Restrict user registration to admin role creation.
\Drupal::configFactory()->getEditable('user.settings')->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)->save(TRUE);
// Allow authenticated users to use shortcuts.
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access shortcuts']);
// Populate the default shortcut set.
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('Add content'),
'weight' => 0,
'link' => ['uri' => 'internal:/node/add'],
]);
$shortcut->save();
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('All content'),
'weight' => 1,
'link' => ['uri' => 'internal:/admin/content'],
]);
$shortcut->save();
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('All media'),
'weight' => 2,
'link' => ['uri' => 'internal:/admin/content/media'],
]);
$shortcut->save();
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('Taxonomy'),
'weight' => 3,
'link' => ['uri' => 'internal:/admin/structure/taxonomy'],
]);
$shortcut->save();
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('Permissions'),
'weight' => 4,
'link' => ['uri' => 'internal:/admin/people/permissions'],
]);
$shortcut->save();
// Allow all users to use search.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['search content']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['search content']);
// Default user theme.
\Drupal::configFactory()->getEditable('system.theme')->set('default', 'drupalcoders_bootstrap')->save(TRUE);
// Enable the admin theme.
\Drupal::configFactory()->getEditable('system.theme')->set('admin', 'adminimal_theme_extras')->save(TRUE);
// Enable the admin theme.
\Drupal::configFactory()->getEditable('node.settings')->set('use_admin_theme', TRUE)->save(TRUE);
// Entity updates to clear up any mismatched entity and/or field definitions
// And Fix changes were detected in the entity type and field definitions.
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
// Can add code in here to make nodes, terms, etc.
}
/**
* Update editor filtered html button settings.
*
* Replaced Ckeditor Widgets with Ckeditor Bootstrap Grid.
*/
function quick_start_update_8001() {
if (\Drupal::moduleHandler()->moduleExists('ckeditor_widgets')) {
\Drupal::service('module_installer')->uninstall(['ckeditor_widgets'], FALSE);
if (!\Drupal::moduleHandler()->moduleExists('ckeditor_bootstrap_grid')) {
\Drupal::service('module_installer')->install(['ckeditor_bootstrap_grid'], FALSE);
$editor_editor_filtered_html_config = \Drupal::service('config.factory')->getEditable('editor.editor.filtered_html');
$editor_editor_filtered_html_config_file = \Drupal::root() . '/' . drupal_get_path('profile', 'quick_start') . '/config/install/editor.editor.filtered_html.yml';
$editor_editor_filtered_html_config_content = file_get_contents($editor_editor_filtered_html_config_file);
$editor_editor_filtered_html_config_content_data = (array) Yaml::parse($editor_editor_filtered_html_config_content);
$editor_editor_filtered_html_config->setData($editor_editor_filtered_html_config_content_data)->save();
}
}
}
