function opigno_learning_path_update_8013 in Opigno Learning path 8
Update Media Browser Images views to remove html tags from fields.
Update Group Members views to remove html tags from fields.
Update translations.
File
- ./
opigno_learning_path.install, line 403 - Install, update and uninstall functions for the module.
Code
function opigno_learning_path_update_8013() {
// Update views.
$display_name = 'default';
$field_name = 'name';
$config_factory = \Drupal::configFactory();
$view = $config_factory
->getEditable('views.view.media_browser_images');
$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);
$display_name = 'default';
$field_name = 'group_roles';
$config_factory = \Drupal::configFactory();
$view = $config_factory
->getEditable('views.view.group_members');
$base = "display.{$display_name}.display_options.fields.{$field_name}";
$view
->set($base . '.empty', t('none'));
$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_learning_path')
->error($e
->getMessage());
}
try {
$lid = $db_connection
->select('locales_source', 'ls')
->fields('ls', [
'lid',
])
->condition('source', '<div class="item-list"><ul><li><none></li></ul></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_learning_path')
->error($e
->getMessage());
}
}