You are here

function simplenews_install in Simplenews 8

Same name and namespace in other branches
  1. 8.2 simplenews.install \simplenews_install()
  2. 5 simplenews.install \simplenews_install()
  3. 6.2 simplenews.install \simplenews_install()
  4. 6 simplenews.install \simplenews_install()
  5. 7.2 simplenews.install \simplenews_install()
  6. 7 simplenews.install \simplenews_install()
  7. 3.x simplenews.install \simplenews_install()

Implements hook_install().

File

./simplenews.install, line 113
Install, update and uninstall functions for the simplenews module

Code

function simplenews_install() {
  if (\Drupal::service('config.installer')
    ->isSyncing()) {
    return;
  }

  // Set the default values for test_address, from_address and from_name.
  $site_mail = \Drupal::config('system.site')
    ->get('mail');
  $site_name = \Drupal::config('system.site')
    ->get('name');
  $config = $config = \Drupal::configFactory()
    ->getEditable('simplenews.settings');
  if (empty($site_mail)) {
    $site_mail = ini_get('sendmail_from');
  }
  $config
    ->set('newsletter.from_address', $site_mail);
  if (empty($site_name)) {
    $site_name = 'Drupal';
  }
  $config
    ->set('newsletter.from_name', $site_name);
  $config
    ->save(TRUE);
  user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array(
    'subscribe to newsletters',
  ));
  user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(
    'subscribe to newsletters',
  ));

  // Init the default newsletter.
  $newsletter = Newsletter::load('default');
  $newsletter->from_name = $site_name;
  $newsletter->from_address = $site_mail;
  $newsletter
    ->trustData();
  $newsletter
    ->save();
}