You are here

function sharemessage_demo_install in Share Message 8

Implements hook_install().

File

modules/sharemessage_demo/sharemessage_demo.install, line 13
Installation hooks for sharemessage_demo module.

Code

function sharemessage_demo_install() {

  // Ensure to rebuild router, as it is lazily rebuild in the module installer.
  \Drupal::service('router.builder')
    ->rebuild();

  // Create an introduction node.
  $description_node = Node::create([
    'title' => t('Share Message demo'),
    'type' => 'sharecontent',
    'uid' => '0',
    'body' => [
      'value' => '<p>' . t('Welcome to the Share Message demo module!') . '</p>' . '<p>' . t('This module provides an exportable entity of share widgets (Share Messages) using the <a href=":addthis">AddThis</a>, <a href=":sharrre">Sharrre</a>, <a href=":ssp">Social Share Privacy</a> or other pluggable share widgets,. It can be used as a block and provides a settings page where the share widget is highly configurable.', [
        ':addthis' => Url::fromUri('http://www.addthis.com/')
          ->toString(),
        ':sharrre' => Url::fromUri('http://www.sharrre.com/')
          ->toString(),
        ':ssp' => Url::fromUri('http://panzi.github.io/SocialSharePrivacy/')
          ->toString(),
      ]) . '</p>' . '<p>' . t('The Share Message demo module includes the configuration needed for enabling social media sharing widgets on a <a href=":drupal">Drupal</a> site.', [
        ':drupal' => Url::fromUri('https://www.drupal.org/')
          ->toString(),
      ]) . '</p>' . '<p>' . t('It contains the default <a href=":settings">Share Message settings</a> and adds a <a href=":demo">Share Message demo</a> with some dummy values to be shared to the <a href=":list">Share Message list</a>.', [
        ':settings' => Url::fromRoute('sharemessage.settings.settings')
          ->toString(),
        ':demo' => Url::fromUri('base:admin/config/services/sharemessage/manage/share_message_addthis_demo')
          ->toString(),
        ':list' => Url::fromRoute('entity.sharemessage.collection')
          ->toString(),
      ]) . '<p>' . '<ul>' . '  <li>' . t('The following share widgets are enabled by default:') . '</li>' . '    <li>' . t('Print,') . '</li>' . '    <li>' . t('Facebook,') . '</li>' . '    <li>' . t('Twitter,') . '</li>' . '    <li>' . t('Gmail,') . '</li>' . '    <li>' . t('Pinterest,') . '</li>' . '    <li>' . t('And many other...') . '</li>' . '</ul>' . '<p>' . t('To display the share widgets on the site, a simple <a href=":block">sharemessage block</a> is added to the top of the first sidebar. The visibility of the block is restricted only to sharecontents.', [
        ':block' => Url::fromRoute('entity.block.edit_form', [
          'block' => 'sharemessage_addthis',
        ])
          ->toString(),
      ]) . '</p>' . '<p>' . t('To get started with the sharing, simply click on a widget in the left sidebar.') . '<p>',
      'format' => 'basic_html',
    ],
  ]);
  $description_node
    ->save();

  // Set the node as the front page.
  \Drupal::configFactory()
    ->getEditable('system.site')
    ->set('page.front', '/node/' . $description_node
    ->id())
    ->save();
  \Drupal::configFactory()
    ->getEditable('sharemessage.sharrre')
    ->set('library_url', '//cdn.jsdelivr.net/sharrre/1.3.4/jquery.sharrre-1.3.4.min.js')
    ->save();
  $services = [
    'googlePlus' => 'googlePlus',
    'facebook' => 'facebook',
    'twitter' => 'twitter',
  ];
  \Drupal::configFactory()
    ->getEditable('sharemessage.sharrre')
    ->set('services', $services)
    ->save();
}