You are here

function opigno_course_update_8004 in Opigno course 8

Update Media Browser Images (png) views to remove html tags from fields.

Update translations.

File

./opigno_course.install, line 109
Install, update and uninstall functions for the Opigno Course module.

Code

function opigno_course_update_8004() {

  // Update views.
  $display_name = 'default';
  $field_name = 'name';
  $config_factory = \Drupal::configFactory();
  $view = $config_factory
    ->getEditable('views.view.media_browser_images_png');
  $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=\"media-info\">\r\n<span class=\"media-info--{{ bundle }}\">{{ bundle }}</span>\r\n{{ name }}\r\n</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_course')
      ->error($e
      ->getMessage());
  }
}