function contact_emails_update_8003 in Contact Emails 8
Modify how the recipient type is stored.
File
- ./
contact_emails.install, line 95 - Contact emails database table.
Code
function contact_emails_update_8003(&$sandbox) {
$connection = \Drupal::database();
$schema = $connection
->schema();
if ($connection
->schema()
->tableExists('contact_message_email_settings')) {
// Add the new recipient field for when the recipient type is field.
$reply_to_type = [
'type' => 'varchar',
'length' => 10,
'not null' => TRUE,
'default' => 'default',
'description' => 'The type of reply-to.',
];
if (!$schema
->fieldExists('contact_message_email_settings', 'reply_to_type')) {
$schema
->addField('contact_message_email_settings', 'reply_to_type', $reply_to_type);
// Update the defaults for existing records.
$query = $connection
->update('contact_message_email_settings');
$query
->fields([
'reply_to_type' => 'default',
]);
$query
->execute();
}
// Reply to field.
$reply_to_field = [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The field to set the reply-to as if reply-to type is field.',
];
if (!$schema
->fieldExists('contact_message_email_settings', 'reply_to_field')) {
$schema
->addField('contact_message_email_settings', 'reply_to_field', $reply_to_field);
}
// Reply to email.
$reply_to_email = [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The email to set the reply-to as if reply-to type is email.',
];
if (!$schema
->fieldExists('contact_message_email_settings', 'reply_to_email')) {
$schema
->addField('contact_message_email_settings', 'reply_to_email', $reply_to_email);
}
}
}