function cms_content_sync_install in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x cms_content_sync.install \cms_content_sync_install()
- 2.0.x cms_content_sync.install \cms_content_sync_install()
Implements hook_install().
- Creates the CMS Content Sync user and provides him with all required permissions.
- Sets module weight so we can hook in after all other content creation modules.
- Displays message to start setting up the site.
File
- ./
cms_content_sync.install, line 64 - Install file for cms_content_sync.
Code
function cms_content_sync_install() {
$config_path = drupal_get_path('module', 'cms_content_sync') . '/config/install';
$source = new FileStorage($config_path);
$config_storage = Drupal::service('config.storage');
$configsNames = [
'key.key.cms_content_sync',
'encrypt.profile.cms_content_sync',
];
foreach ($configsNames as $name) {
$config_storage
->write($name, $source
->read($name));
}
$username = 'CMS Content Sync';
Drupal::moduleHandler()
->alter('cms_content_sync_username', $username);
$data = [
'userName' => $username,
'userPass' => user_password(),
];
$user = User::create();
$user
->setUsername($data['userName']);
$user
->setPassword($data['userPass']);
$user
->enforceIsNew();
$user
->activate();
$user
->addRole('cms_content_sync');
$user
->save();
// Store UID in key value table.
Drupal::service('keyvalue.database')
->get('cms_content_sync_user')
->set('uid', intval($user
->id()));
$data = cms_content_sync_encrypt_values($data);
$userData = Drupal::service('user.data');
$userData
->set('cms_content_sync', $user
->id(), 'sync_data', $data);
_cms_content_sync_set_module_weight();
Drupal::messenger()
->addStatus(new FormattableMarkup("Thanks for choosing Content Sync! @start.", [
'@start' => Link::createFromRoute("Setup your first content pool now", "entity.cms_content_sync_pool.add_form")
->toString(),
]));
Drupal::messenger()
->addStatus(new FormattableMarkup('If you have connected another site already, @copy. Mirroring means you can simply swap the push and pull settings.', [
'@copy' => Link::createFromRoute("copy or mirror the configuration from another site", "entity.cms_content_sync_flow.copy_remote")
->toString(),
]));
}