You are here

opigno_calendar.install in Opigno calendar 8

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

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

File

opigno_calendar.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Opigno Calendar module.
 */
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Config\FileStorage;

/**
 * Creates the members field in the opigno calendar event type.
 */
function opigno_calendar_update_8001() {
  $config_path = drupal_get_path('module', 'opigno_calendar') . '/config/install';
  $storage = new FileStorage($config_path);
  $data = $storage
    ->read('field.storage.opigno_calendar_event.field_calendar_event_members');
  if (!FieldStorageConfig::loadByName($data['entity_type'], $data['field_name'])) {
    FieldStorageConfig::create($data)
      ->save();
  }
  $data = $storage
    ->read('field.field.opigno_calendar_event.opigno_calendar_event.field_calendar_event_members');
  if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
    FieldConfig::create($data)
      ->save();
  }
}

/**
 * Updates Opigno Calendar views to remove html tags from fields.
 *
 * Update translations.
 */
function opigno_calendar_update_8002() {

  // Update views.
  $display_name = 'month_block';
  $field_name = 'date_daterange';
  $config_factory = \Drupal::configFactory();
  $view = $config_factory
    ->getEditable('views.view.opigno_calendar');
  $displays = $view
    ->get('display');
  $alter_option = $displays[$display_name]['display_options']['fields'][$field_name]['alter'];
  $alter_option['alter_text'] = FALSE;
  $alter_option['text'] = '';
  $base = "display.{$display_name}.display_options.fields.{$field_name}";
  $view
    ->set($base . '.alter', $alter_option);
  $view
    ->save(TRUE);
  if (!\Drupal::moduleHandler()
    ->moduleExists('locale')) {
    return;
  }

  // Update translations.
  $db_connection = \Drupal::service('database');

  // Get id of translation.
  try {
    $lid = $db_connection
      ->select('locales_source', 'ls')
      ->fields('ls', [
      'lid',
    ])
      ->condition('source', '<div class="time">{{ date_daterange }}</div>')
      ->execute()
      ->fetchField();
    if ($lid) {

      // Remove sourse translation.
      $db_connection
        ->delete('locales_source')
        ->condition('lid', $lid)
        ->execute();

      // Remove target translation.
      $db_connection
        ->delete('locales_target')
        ->condition('lid', $lid)
        ->execute();
    }
  } catch (Exception $e) {
    \Drupal::logger('opigno_calendar')
      ->error($e
      ->getMessage());
  }
}

/**
 * Adding Datepicker date format.
 */
function opigno_calendar_update_8003() {
  $config_path = drupal_get_path('module', 'opigno_calendar') . '/config/install';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('core.date_format.datepicker');
  $config_storage
    ->write('core.date_format.datepicker', $data);
}

/**
 * Show tabs on calendar page.
 */
function opigno_calendar_update_8004() {
  $theme_handler = Drupal::service('theme_handler');
  $info = $theme_handler
    ->listInfo();
  if (isset($info['platon'])) {
    $config_path = drupal_get_path('theme', 'platon') . '/config/optional';
    $storage = new FileStorage($config_path);
    $config_storage = \Drupal::service('config.storage');
    $data = $storage
      ->read('block.block.tabs');
    $config_storage
      ->write('block.block.tabs', $data);
  }
}

/**
 * Hide tabs on calendar month page.
 */
function opigno_calendar_update_8005() {
  $theme_handler = Drupal::service('theme_handler');
  $info = $theme_handler
    ->listInfo();
  if (isset($info['platon'])) {
    $config_path = drupal_get_path('theme', 'platon') . '/config/optional';
    $storage = new FileStorage($config_path);
    $config_storage = \Drupal::service('config.storage');
    $data = $storage
      ->read('block.block.tabs');
    $config_storage
      ->write('block.block.tabs', $data);
  }
}

/**
 * Added title for calendar page to improve accessibility.
 */
function opigno_calendar_update_8006() {
  $config_path = drupal_get_path('module', 'opigno_calendar') . '/config/install';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('views.view.opigno_calendar');
  $config_storage
    ->write('views.view.opigno_calendar', $data);
}

Functions

Namesort descending Description
opigno_calendar_update_8001 Creates the members field in the opigno calendar event type.
opigno_calendar_update_8002 Updates Opigno Calendar views to remove html tags from fields.
opigno_calendar_update_8003 Adding Datepicker date format.
opigno_calendar_update_8004 Show tabs on calendar page.
opigno_calendar_update_8005 Hide tabs on calendar month page.
opigno_calendar_update_8006 Added title for calendar page to improve accessibility.