You are here

opigno_messaging.install in Opigno messaging 8

Same filename and directory in other branches
  1. 3.x opigno_messaging.install

Install, update and uninstall functions for the Opigno Messaging module.

File

opigno_messaging.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Opigno Messaging module.
 */
use Drupal\Core\Config\FileStorage;
use Drupal\block\Entity\Block;

/**
 * Alter private_messages module configuration.
 *
 * On module install.
 */
function opigno_messaging_install($is_syncing) {
  if (!$is_syncing) {

    // private_message_thread.
    $config = \Drupal::configFactory()
      ->getEditable('core.entity_view_display.private_message_thread.private_message_thread.default');
    $cfg = $config
      ->get();
    $cfg['content']['field_pm_subject'] = [
      'label' => 'above',
      'region' => 'content',
      'weight' => -99,
      'type' => 'string',
      'third_party_settings' => [],
      'settings' => [
        'link_to_entity' => FALSE,
      ],
    ];
    unset($cfg['hidden']['field_pm_subject']);
    $cfg['content']['delete_link']['weight'] = -100;
    $cfg['content']['members']['label'] = 'hidden';
    $cfg['content']['private_messages']['label'] = 'hidden';
    $config
      ->setData($cfg)
      ->save();

    // private_message.
    $config = \Drupal::configFactory()
      ->getEditable('core.entity_view_display.private_message.private_message.default');
    $cfg = $config
      ->get();
    $cfg['content']['owner']['label'] = 'hidden';
    $cfg['hidden']['created'] = TRUE;
    unset($cfg['content']['created']);
    $config
      ->setData($cfg)
      ->save();
  }
}

/**
 * Reload private messages views config for removing caching.
 */
function opigno_messaging_update_8001() {
  $config_path = drupal_get_path('module', 'opigno_messaging') . '/config/optional';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('views.view.private_message');
  $config_storage
    ->write('views.view.private_message', $data);
}

/**
 * Update private messages main menu link.
 */
function opigno_messaging_update_8004() {
  $menu_name = 'main';
  $storage = \Drupal::entityTypeManager()
    ->getStorage('menu_link_content');
  $menu_links = $storage
    ->loadByProperties([
    'menu_name' => $menu_name,
  ]);
  foreach ($menu_links as $menu_link) {
    if ($menu_link
      ->getTitle() == 'Messages') {
      $menu_link
        ->set('link', [
        'uri' => 'internal:/private-messages',
      ]);
      $menu_link
        ->save();
      break;
    }
  }
}

/**
 * Update new private message link on private-messages page.
 */
function opigno_messaging_update_8005() {
  $config_path = drupal_get_path('module', 'opigno_messaging') . '/config/optional';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('views.view.private_message');
  $config_storage
    ->write('views.view.private_message', $data);
}

/**
 * Update private messages views header link with base path.
 */
function opigno_messaging_update_8007() {
  $config_path = drupal_get_path('module', 'opigno_messaging') . '/config/optional';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('views.view.private_message');
  $data['display']['default']['display_options']['header']['area_text_custom']['content'] = '<a class="new-message" href="[opigno:url-with-slash]private-message/create">New message</a><p class="messages">Messages</p>';
  $config_storage
    ->write('views.view.private_message', $data);
}

/**
 * Update private messages block all.
 */
function opigno_messaging_update_8008() {
  try {
    $block = Block::load('views_block__private_message_block_all');
    $visibility = $block
      ->getVisibility();
    $visibility['request_path']['pages'] = "/private-messages\r\n/private-messages/*\r\n/private-message/*";
    $block
      ->setVisibilityConfig('request_path', $visibility['request_path']);
    $block
      ->save();
  } catch (\Exception $e) {
    \Drupal::logger('opigno_messaging')
      ->error($e
      ->getMessage());
    \Drupal::messenger()
      ->addMessage($e
      ->getMessage(), 'error');
  }
}

/**
 * Update private messages views header link with base path.
 */
function opigno_messaging_update_8009() {
  $config_path = drupal_get_path('module', 'opigno_messaging') . '/config/optional';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('views.view.private_message');
  $data['display']['default']['display_options']['header']['area_text_custom']['content'] = '<a class="new-message" href="[opigno:url-with-slash]private-message/create">New message</a><h2 class="messages">Messages</h2>';
  $config_storage
    ->write('views.view.private_message', $data);
}

/**
 * Update private messages views header link with icons.
 */
function opigno_messaging_update_8010() {
  $config_path = drupal_get_path('module', 'opigno_messaging') . '/config/optional';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('views.view.private_message');
  $data['display']['default']['display_options']['header']['area_text_custom']['content'] = '<a class="new-message" href="[opigno:url-with-slash]private-message/create"><i class="icon-plus"></i>New message</a><h2 class="messages">Messages</h2>';
  $config_storage
    ->write('views.view.private_message', $data);
}

Functions

Namesort descending Description
opigno_messaging_install Alter private_messages module configuration.
opigno_messaging_update_8001 Reload private messages views config for removing caching.
opigno_messaging_update_8004 Update private messages main menu link.
opigno_messaging_update_8005 Update new private message link on private-messages page.
opigno_messaging_update_8007 Update private messages views header link with base path.
opigno_messaging_update_8008 Update private messages block all.
opigno_messaging_update_8009 Update private messages views header link with base path.
opigno_messaging_update_8010 Update private messages views header link with icons.