diff --git a/core/modules/taxonomy/src/Form/OverviewTerms.php b/core/modules/taxonomy/src/Form/OverviewTerms.php index 3811ee5fd8..1b940ce68d 100644 --- a/core/modules/taxonomy/src/Form/OverviewTerms.php +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php @@ -2,6 +2,7 @@ namespace Drupal\taxonomy\Form; +use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -29,6 +30,13 @@ class OverviewTerms extends FormBase { protected $entityManager; /** + * The database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $database; + + /** * The term storage handler. * * @var \Drupal\taxonomy\TermStorageInterface @@ -42,10 +50,13 @@ class OverviewTerms extends FormBase { * The module handler service. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. + * @param \Drupal\Core\Database\Connection + * The database connection. */ - public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager) { + public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager, Connection $database) { $this->moduleHandler = $module_handler; $this->entityManager = $entity_manager; + $this->database = $database; $this->storageController = $entity_manager->getStorage('taxonomy_term'); } @@ -55,7 +66,8 @@ public function __construct(ModuleHandlerInterface $module_handler, EntityManage public static function create(ContainerInterface $container) { return new static( $container->get('module_handler'), - $container->get('entity.manager') + $container->get('entity.manager'), + $container->get('database') ); } @@ -203,6 +215,15 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular } } + // Get IDs of terms which have pending revisions. + $pending_term_ids = $this->getTermsWithPendingRevisions($taxonomy_vocabulary); + if (!empty($pending_term_ids)) { + $warning = $this->formatPlural(count($pending_term_ids), + 'There is 1 term (marked with a *) with pending revisions. Reorganizing the terms could result in losing the pending revisions.', + 'There is @count terms (marked with a *) with pending revisions. Reorganizing the terms could result in losing the pending revisions.'); + drupal_set_message($warning, 'warning'); + } + $errors = $form_state->getErrors(); $destination = $this->getDestinationArray(); $row_position = 0; @@ -230,6 +251,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular '#prefix' => !empty($indentation) ? \Drupal::service('renderer')->render($indentation) : '', '#type' => 'link', '#title' => $term->getName(), + '#suffix' => in_array($term->id(), $pending_term_ids) ? '*' : '', '#url' => $term->urlInfo(), ]; if ($taxonomy_vocabulary->getHierarchy() != VocabularyInterface::HIERARCHY_MULTIPLE && count($tree) > 1) { @@ -474,4 +496,27 @@ public function submitReset(array &$form, FormStateInterface $form_state) { $form_state->setRedirectUrl($vocabulary->urlInfo('reset-form')); } + /** + * Finds all terms which have a newer revision than the default. + * + * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary + * + * @return array + */ + protected function getTermsWithPendingRevisions(VocabularyInterface $taxonomy_vocabulary) { + $term_definition = $this->entityManager->getDefinition('taxonomy_term'); + $id_key = $term_definition->getKey('id'); + $revision_key = $term_definition->getKey('revision'); + $base_table = $term_definition->getBaseTable(); + $revision_table = $term_definition->getRevisionTable(); + $query = $this->database + ->select($revision_table, 'ttr') + ->fields('ttr', [$id_key]); + $query->join($base_table, 'ttd', 'ttr.' . $id_key . ' = ttd.' . $id_key); + return $query->where('ttr.' . $revision_key . ' > ttd.' . $revision_key) + ->groupBy($id_key) + ->execute() + ->fetchCol(); + } + }