diff --git a/core/modules/forum/src/Form/Overview.php b/core/modules/forum/src/Form/Overview.php index 24e4a92..df6f947 100644 --- a/core/modules/forum/src/Form/Overview.php +++ b/core/modules/forum/src/Form/Overview.php @@ -2,7 +2,6 @@ namespace Drupal\forum\Form; -use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; @@ -30,11 +29,9 @@ class Overview extends OverviewTerms { * The module handler service. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. - * @param \Drupal\Core\DatabaseConnection - * The database connection. */ - public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager, Connection $database) { - parent::__construct($module_handler, $entity_manager, $database); + public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager) { + parent::__construct($module_handler, $entity_manager); $this->entityManager = $entity_manager; } diff --git a/core/modules/system/css/components/tabledrag.module.css b/core/modules/system/css/components/tabledrag.module.css index b3c3ef0..a4f0f20 100644 --- a/core/modules/system/css/components/tabledrag.module.css +++ b/core/modules/system/css/components/tabledrag.module.css @@ -47,9 +47,6 @@ a.tabledrag-handle:hover .handle, a.tabledrag-handle:focus .handle { background-image: url(../../../../misc/icons/000000/move.svg); } -tr.pending-revision a.tabledrag-handle .handle { - background-image: url(../../../../misc/icons/e29700/warning.svg); -} .touchevents .draggable td { padding: 0 10px; } diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoBundle.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoBundle.php index 5907021..1c504f7 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoBundle.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestNoBundle.php @@ -12,6 +12,7 @@ * entity_keys = { * "id" = "id", * "revision" = "revision_id", + * "label" = "name", * }, * admin_permission = "administer entity_test content", * links = { diff --git a/core/modules/taxonomy/src/Form/OverviewTerms.php b/core/modules/taxonomy/src/Form/OverviewTerms.php index 89e399e..fc259d0 100644 --- a/core/modules/taxonomy/src/Form/OverviewTerms.php +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php @@ -2,7 +2,7 @@ namespace Drupal\taxonomy\Form; -use Drupal\Core\Database\Connection; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -30,13 +30,6 @@ class OverviewTerms extends FormBase { protected $entityManager; /** - * The database connection. - * - * @var \Drupal\Core\Database\Connection - */ - protected $database; - - /** * The term storage handler. * * @var \Drupal\taxonomy\TermStorageInterface @@ -50,13 +43,10 @@ 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, Connection $database) { + public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager) { $this->moduleHandler = $module_handler; $this->entityManager = $entity_manager; - $this->database = $database; $this->storageController = $entity_manager->getStorage('taxonomy_term'); } @@ -66,8 +56,7 @@ 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('database') + $container->get('entity.manager') ); } @@ -215,13 +204,42 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular } } + switch ($taxonomy_vocabulary->getHierarchy()) { + case VocabularyInterface::HIERARCHY_DISABLED: + $help_message = $this->t('You can reorganize the terms in %capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', [ + '%capital_name' => Unicode::ucfirst($taxonomy_vocabulary->label()), + '%name' => $taxonomy_vocabulary->label() + ]); + break; + case VocabularyInterface::HIERARCHY_MULTIPLE: + $help_message = $this->t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', ['%capital_name' => Unicode::ucfirst($taxonomy_vocabulary->label())]); + break; + case VocabularyInterface::HIERARCHY_SINGLE: + default: + $help_message = $this->t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', [ + '%capital_name' => Unicode::ucfirst($taxonomy_vocabulary->label()), + '%name' => $taxonomy_vocabulary->label() + ]); + break; + } + // 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 with pending revisions. Publish this term before reorganising.', - 'There is @count terms with pending revisions. Publish these terms before reorganising.'); - drupal_set_message($warning, 'warning'); + $help_message = $this->formatPlural( + count($pending_term_ids), + '%capital_name contains 1 term with pending revisions. Drag and drop of terms with pending revisions is not supported, but you can re-enable drag-and-drop support by getting each term to a published state.', + '%capital_name contains @count terms with pending revisions. Drag and drop of terms with pending revisions is not supported, but you can re-enable drag-and-drop support by getting each term to a published state.', + ['%capital_name' => Unicode::ucfirst($taxonomy_vocabulary->label())] + ); + } + + $form['help'] = [ + '#type' => 'container', + 'message' => ['#markup' => $help_message], + ]; + if (!empty($pending_term_ids) || $taxonomy_vocabulary->getHierarchy() === VocabularyInterface::HIERARCHY_MULTIPLE) { + $form['help']['#attributes']['class'] = ['messages', 'messages--warning']; } $errors = $form_state->getErrors(); @@ -254,8 +272,10 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular '#url' => $term->urlInfo(), ]; + // Add a special class for terms with pending revision so we can highlight + // them in the form. if (in_array($term->id(), $pending_term_ids)) { - $form['terms'][$key]['#attributes']['class'][] = 'pending-revision'; + $form['terms'][$key]['#attributes']['class'][] = 'color-warning'; } if ($taxonomy_vocabulary->getHierarchy() != VocabularyInterface::HIERARCHY_MULTIPLE && count($tree) > 1) { @@ -374,19 +394,17 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular 'group' => 'term-weight', ]; - if ($taxonomy_vocabulary->getHierarchy() != VocabularyInterface::HIERARCHY_MULTIPLE && count($tree) > 1) { + if ($taxonomy_vocabulary->getHierarchy() != VocabularyInterface::HIERARCHY_MULTIPLE && count($tree) > 1 && empty($pending_term_ids)) { $form['actions'] = ['#type' => 'actions', '#tree' => FALSE]; $form['actions']['submit'] = [ '#type' => 'submit', '#value' => $this->t('Save'), '#button_type' => 'primary', - '#disabled' => !empty($pending_term_ids), ]; $form['actions']['reset_alphabetical'] = [ '#type' => 'submit', '#submit' => ['::submitReset'], '#value' => $this->t('Reset to alphabetical'), - '#disabled' => !empty($pending_term_ids), ]; } @@ -502,26 +520,28 @@ public function submitReset(array &$form, FormStateInterface $form_state) { } /** - * Finds all terms which have a newer revision than the default. + * Gets the terms with pending revisions from a vocabulary. * - * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary + * @param \Drupal\taxonomy\VocabularyInterface $vocabulary + * A taxonomy vocabulary. * * @return array + * An array of term IDs which have pending revisions, keyed by revision IDs. */ - 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(); + protected function getTermsWithPendingRevisions(VocabularyInterface $vocabulary) { + $entity_type = $this->entityManager->getDefinition('taxonomy_term'); + + $query = $this->storageController->getQuery() + ->condition($entity_type->getKey('bundle'), $vocabulary->id(), '=') + ->sort($entity_type->getKey('revision'), 'DESC'); + $default_revisions = $query->execute(); + + $latest_revisions = (clone $query) + ->allRevisions() + ->execute(); + $latest_revisions = array_unique($latest_revisions); + + return array_diff_key($latest_revisions, $default_revisions); } } diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 11c959f..cf247d4 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -72,17 +72,6 @@ function taxonomy_help($route_name, RouteMatchInterface $route_match) { case 'entity.taxonomy_vocabulary.collection': $output = '

' . t('Taxonomy is for categorizing content. Terms are grouped into vocabularies. For example, a vocabulary called "Fruit" would contain the terms "Apple" and "Banana".') . '

'; return $output; - - case 'entity.taxonomy_vocabulary.overview_form': - $vocabulary = $route_match->getParameter('taxonomy_vocabulary'); - switch ($vocabulary->getHierarchy()) { - case VocabularyInterface::HIERARCHY_DISABLED: - return '

' . t('You can reorganize the terms in %capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', ['%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label()]) . '

'; - case VocabularyInterface::HIERARCHY_SINGLE: - return '

' . t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', ['%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label()]) . '

'; - case VocabularyInterface::HIERARCHY_MULTIPLE: - return '

' . t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '

'; - } } } diff --git a/core/themes/stable/css/system/components/tabledrag.module.css b/core/themes/stable/css/system/components/tabledrag.module.css index dadd587..687bdc2 100644 --- a/core/themes/stable/css/system/components/tabledrag.module.css +++ b/core/themes/stable/css/system/components/tabledrag.module.css @@ -47,9 +47,6 @@ a.tabledrag-handle:hover .handle, a.tabledrag-handle:focus .handle { background-image: url(../../../images/core/icons/000000/move.svg); } -tr.pending-revision a.tabledrag-handle .handle { - background-image: url(../../../images/core/icons/e29700/warning.svg); -} .touchevents .draggable td { padding: 0 10px; }