You are here

function opigno_module_update_8015 in Opigno module 8

Update Media Browser (File(PDF)) views to remove html tags from fields.

Update translations.

File

./opigno_module.install, line 944
Opigno module app install/update functionality.

Code

function opigno_module_update_8015() {

  // Update views.
  $display_name = 'default';
  $field_name = 'name';
  $config_factory = \Drupal::configFactory();
  $view = $config_factory
    ->getEditable('views.view.media_browser_file_pdf');
  $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);
  $config_factory = \Drupal::configFactory();
  $view = $config_factory
    ->getEditable('views.view.opigno_score_modules');
  $data = $view
    ->getRawData();
  $data['display'][$display_name]['display_options']['empty']['area']['content']['value'] = t('There are no module to evaluate');
  $view
    ->setData($data);
  $view
    ->save(TRUE);
  if (!\Drupal::moduleHandler()
    ->moduleExists('locale')) {
    return;
  }

  // Update translations.

  /* @var \Drupal\Core\Database\Connection $db_connection */
  $db_connection = \Drupal::service('database');

  // Get id of translation.
  try {
    if ($db_connection
      ->schema()
      ->tableExists('locales_source')) {
      $lid = $db_connection
        ->select('locales_source', 'ls')
        ->fields('ls', [
        'lid',
      ])
        ->condition('source', "<div class=\"no-result-behaviour\"'>\nThere are no module to evaluate\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_module')
      ->error($e
      ->getMessage());
  }
}