You are here

function opigno_calendar_update_8002 in Opigno calendar 8

Updates Opigno Calendar views to remove html tags from fields.

Update translations.

File

./opigno_calendar.install, line 36
Install, update and uninstall functions for the Opigno Calendar module.

Code

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());
  }
}