You are here

social_sharing.install in Open Social 10.0.x

The Social Sharing install.

File

modules/social_features/social_sharing/social_sharing.install
View source
<?php

/**
 * @file
 * The Social Sharing install.
 */
use Drupal\block\Entity\Block;
use Drupal\Core\Entity\EntityStorageException;

/**
 * Install social_sharing.
 */
function social_sharing_install() {

  // Default shariff settings.
  _social_sharing_shariff_settings();
}

/**
 * Remove the old Addtoany bocks.
 */
function social_sharing_update_8001() {

  // Enable shariff.
  \Drupal::service('module_installer')
    ->install([
    'shariff',
  ]);

  // Default shariff settings.
  _social_sharing_shariff_settings();
  $blocks = Block::loadMultiple([
    'addtoanybuttons',
    'addtoanybuttons_2',
  ]);
  foreach ($blocks as $block) {
    try {
      $block
        ->delete();
    } catch (EntityStorageException $e) {

      // Add the error to watchdog.
      \Drupal::messenger()
        ->addMessage($e
        ->getMessage());
    }
  }
}

/**
 * Remove the old Addtoany bocks.
 */
function _social_sharing_shariff_settings() {

  // Get the current array of enabled services.
  $services = \Drupal::configFactory()
    ->getEditable('shariff.settings')
    ->get('shariff_services');

  // Add 'add this'.
  $services['addthis'] = 'addthis';
  \Drupal::configFactory()
    ->getEditable('shariff.settings')
    ->set('shariff_services', $services)
    ->save();
}

Functions

Namesort descending Description
social_sharing_install Install social_sharing.
social_sharing_update_8001 Remove the old Addtoany bocks.
_social_sharing_shariff_settings Remove the old Addtoany bocks.