contacts-8.x-1.x-dev/contacts.install
contacts.install
<?php
/**
* @file
* Install related hook implementations for the contacts module.
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
/**
* Implements hook_schema().
*/
function contacts_schema() {
$schema['contacts_duplicate_exclusions'] = [
'description' => 'Users excluded from deduplication.',
'fields' => [
'uid1' => [
'type' => 'int',
'not null' => TRUE,
],
'uid2' => [
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => ['uid1', 'uid2'],
];
return $schema;
}
/**
* Implements hook_modules_installed().
*/
function contacts_modules_installed($modules, $is_syncing) {
if (!$is_syncing) {
// Once contacts has been installed, install contacts_group too.
// This is necessary because contacts_group is required for contacts
// to operate properly, creating a circular dependency.
// Refactoring it so that contacts_group functionality is directly inside
// contacts is too much of a breaking change, so automatically install the
// submodule instead.
// Note that this logic used to be inside `contacts_install`,
// but moved to contacts_modules_installed as of Drupal 11.2 as
// contacts_install is now too early and generates missing config errors.
if (in_array('contacts', $modules)) {
drupal_flush_all_caches();
/** @var \Drupal\Core\Extension\ModuleInstaller $module_installer */
$module_installer = \Drupal::service('module_installer');
$module_installer->install(['contacts_group']);
}
}
}
/**
* Add duplicate_exclusions.
*/
function contacts_update_8001() {
$table = [
'description' => 'Users excluded from deduplication.',
'fields' => [
'uid1' => [
'type' => 'int',
'not null' => TRUE,
],
'uid2' => [
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => ['uid1', 'uid2'],
];
$schema = Database::getConnection()->schema();
$schema->createTable('contacts_duplicate_exclusions', $table);
}
/**
* Pseudo-email field configuration.
*/
function contacts_update_8002() {
// Email should be required for the crm_indiv profile/role.
\Drupal::configFactory()
->getEditable('contacts.configuration')
->set('email_required_roles', ['crm_indiv'])
->save();
// Add the email into the Add Contact form displays for crm_org/crm_indiv.
/** @var \Drupal\Core\Entity\Entity\EntityFormDisplay $form_display */
$form_display = EntityFormDisplay::load('profile.crm_indiv.add_contact');
if ($form_display) {
$form_display->setComponent('contacts_mail', [
'weight' => -1,
]);
$form_display->save();
}
$form_display = EntityFormDisplay::load('profile.crm_org.add_contact');
if ($form_display) {
$form_display->setComponent('contacts_mail', [
'weight' => -1,
]);
$form_display->save();
}
}
