Skip to content
Snippets Groups Projects
Commit 21f667e2 authored by lpeidro's avatar lpeidro Committed by Luis Ruiz Peidró
Browse files

Issue #3500565: Improve texts and show all languages in Original content

parent 718b3427
No related branches found
No related tags found
No related merge requests found
...@@ -151,10 +151,18 @@ function entity_mesh_alter_node_delete_form(&$form, NodeInterface $node) { ...@@ -151,10 +151,18 @@ function entity_mesh_alter_node_delete_form(&$form, NodeInterface $node) {
$node_id = $node->id(); $node_id = $node->id();
$label = $node->label(); $label = $node->label();
// Check if the site has the service Language Manager. $language_to_show = 'undifined';
$current_language = NULL; $languages = [];
if (\Drupal::hasService('language_manager')) { if (\Drupal::hasService('language_manager')) {
$current_language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$languages = array_map(function ($language) {
// Example: Add a suffix to each language name.
return $language->getName();
}, \Drupal::languageManager()->getLanguages());
$default_lang_id = \Drupal::languageManager()->getDefaultLanguage()->getId();
$node_lang = $node->language()->getId();
$language_to_show = $node_lang !== $default_lang_id ? $node_lang : 'all';
} }
// Define the basic query. // Define the basic query.
...@@ -179,19 +187,7 @@ function entity_mesh_alter_node_delete_form(&$form, NodeInterface $node) { ...@@ -179,19 +187,7 @@ function entity_mesh_alter_node_delete_form(&$form, NodeInterface $node) {
return; return;
} }
// If there are a big amount of references, we show a warning
// message without the node list.
if ($count > 20) {
$form[$node_id] = [
'#type' => 'html_tag',
'#tag' => 'h4',
'#value' => t('There are @count references to "@label". Please review this case carefully before proceeding with the deletion.', ['@count' => $count, '@label' => $label]),
];
return;
}
$items = []; $items = [];
$history = [];
$execution = $query->execute(); $execution = $query->execute();
$execution = $execution->fetchAll(); $execution = $execution->fetchAll();
...@@ -199,25 +195,48 @@ function entity_mesh_alter_node_delete_form(&$form, NodeInterface $node) { ...@@ -199,25 +195,48 @@ function entity_mesh_alter_node_delete_form(&$form, NodeInterface $node) {
// only expose the link to the current language. // only expose the link to the current language.
foreach ($execution as $record) { foreach ($execution as $record) {
$index = $record->source_entity_type . '-' . $record->source_entity_id; $index = $record->source_entity_type . '-' . $record->source_entity_id;
if ($current_language && isset($history[$index])) { $language = $record->source_entity_langcode ?? 'undifined';
continue;
if (isset($items[$language])) {
$items[$language] = [];
} }
$items[$index] = Link::fromTextAndUrl(
$items[$language][$index] = Link::fromTextAndUrl(
$record->source_title, $record->source_title,
Url::fromRoute('entity.node.canonical', ['node' => $record->source_entity_id]) Url::fromRoute('entity.node.canonical', ['node' => $record->source_entity_id])
); );
if ($current_language && $record->source_entity_langcode !== $current_language) {
$history[$index] = $current_language;
}
} }
$form[$node_id]['title'] = [ $form[$node_id]['title'] = [
'#type' => 'html_tag', '#type' => 'html_tag',
'#tag' => 'h4', '#tag' => 'p',
'#value' => t('The following contents refer to "@label". Please review them before proceeding with the deletion.', ['@label' => $label]), '#value' => t('Warning: "@label" is linked from other content listed below. Deleting it may result in broken references that should be updated', ['@label' => $label]),
]; ];
if ($language_to_show !== 'all') {
$item_list = $items[$language_to_show] ?? [];
if (count($item_list) === 0) {
unset($form[$node_id]);
return;
}
$form[$node_id]['items'] = [ $form[$node_id]['items'] = [
'#theme' => 'item_list', '#theme' => 'item_list',
'#items' => $items, '#items' => $item_list,
]; ];
return;
}
foreach ($items as $lang => $item_list) {
$lang_label = $languages[$lang] ?? '';
$form[$node_id][$lang]['text'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => t('@lang', ['@lang' => $lang_label]),
];
$form[$node_id][$lang]['items'] = [
'#theme' => 'item_list',
'#items' => $item_list,
];
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment