diff --git a/src/ParamConverter/EntityRevisionConverter.php b/src/ParamConverter/EntityRevisionConverter.php index eefd4f6..8036293 100644 --- a/src/ParamConverter/EntityRevisionConverter.php +++ b/src/ParamConverter/EntityRevisionConverter.php @@ -39,7 +39,9 @@ class EntityRevisionConverter extends EntityConverter { * {@inheritdoc} */ public function applies($definition, $name, Route $route) { - return $this->hasForwardRevisionFlag($definition) || $this->isEditFormPage($route); + return $this->hasForwardRevisionFlag($definition) + || $this->isEditFormPage($route) + || $this->isQuickeditRoute($route); } /** @@ -81,6 +83,29 @@ class EntityRevisionConverter extends EntityConverter { } /** + * Determines if a given route is related to Quickedit. + * + * @param \Symfony\Component\Routing\Route $route + * The route definition. + * + * @return bool + * Returns TRUE if the route is related to Quickedit, FALSE otherwise. + */ + protected function isQuickeditRoute(Route $route) { + $compatible_routes = [ + '/quickedit/form/{entity_type}/{entity}/{field_name}/{langcode}/{view_mode_id}', + '/quickedit/entity/{entity_type}/{entity}', + '/editor/{entity_type}/{entity}/{field_name}/{langcode}/{view_mode_id}', + '/quickedit/image/upload/{entity_type}/{entity}/{field_name}/{langcode}/{view_mode_id}', + '/quickedit/image/info/{entity_type}/{entity}/{field_name}/{langcode}/{view_mode_id}' + ]; + if (in_array($route->getPath(), $compatible_routes)) { + return TRUE; + } + return FALSE; + } + + /** * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults) { diff --git a/src/Plugin/Field/FieldWidget/ModerationStateWidget.php b/src/Plugin/Field/FieldWidget/ModerationStateWidget.php index b1fd2f7..1135bb0 100644 --- a/src/Plugin/Field/FieldWidget/ModerationStateWidget.php +++ b/src/Plugin/Field/FieldWidget/ModerationStateWidget.php @@ -4,6 +4,7 @@ namespace Drupal\workbench_moderation\Plugin\Field\FieldWidget; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\EntityFormInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\Query\QueryInterface; @@ -193,6 +194,12 @@ class ModerationStateWidget extends OptionsSelectWidget implements ContainerFact * Process callback to alter action buttons. */ public static function processActions($element, FormStateInterface $form_state, array &$form) { + $form_object = $form_state->getFormObject(); + + // Return early if this isn't an Entity Form (i.e. the QuickEditFieldForm). + if (!($form_object instanceof EntityFormInterface)) { + return $element; + } // We'll steal most of the button configuration from the default submit button. // However, NodeForm also hides that button for admins (as it adds its own, @@ -204,7 +211,7 @@ class ModerationStateWidget extends OptionsSelectWidget implements ContainerFact // property tells FAPI to cluster them all together into a single widget. $options = $element['#options']; - $entity = $form_state->getFormObject()->getEntity(); + $entity = $form_object->getEntity(); $translatable = !$entity->isNew() && $entity->isTranslatable(); foreach ($options as $id => $label) { $button = [ diff --git a/workbench_moderation.module b/workbench_moderation.module index fe6ec99..34878f5 100644 --- a/workbench_moderation.module +++ b/workbench_moderation.module @@ -65,6 +65,34 @@ function workbench_moderation_entity_view_alter(&$build, EntityInterface $entity } /** + * Implements hook_node_view_alter(). + */ +function workbench_moderation_node_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) { + /** @var \Drupal\workbench_moderation\ModerationInformationInterface $mod_info */ + $mod_info = \Drupal::service('workbench_moderation.moderation_information'); + /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */ + $module_handler = \Drupal::service('module_handler'); + // Show standard node contextual links on node drafts. + if ($mod_info->isLatestRevision($entity)) { + if (isset($build['#contextual_links']['node_revision'])) { + unset($build['#contextual_links']['node_revision']); + $build['#contextual_links']['node'] = [ + 'route_parameters' => ['node' => $entity->id()], + 'metadata' => ['changed' => $entity->getChangedTime()], + ]; + } + } + // Disable Quick Edit when viewing individual revisions. + if ($module_handler->moduleExists('quickedit')) { + $route_match = \Drupal::routeMatch(); + $match = $route_match->getCurrentRouteMatch(); + if ($match->getRouteName() === 'entity.node.revision') { + $build['#attributes']['data-quickedit-disable'] = TRUE; + } + } +} + +/** * Implements hook_entity_type_alter(). */ function workbench_moderation_entity_type_alter(array &$entity_types) { diff --git a/workbench_moderation.services.yml b/workbench_moderation.services.yml index 330e91a..215521a 100644 --- a/workbench_moderation.services.yml +++ b/workbench_moderation.services.yml @@ -3,7 +3,7 @@ services: class: Drupal\workbench_moderation\ParamConverter\EntityRevisionConverter arguments: ['@entity.manager', '@workbench_moderation.moderation_information'] tags: - - { name: paramconverter, priority: 5 } + - { name: paramconverter, priority: 6 } workbench_moderation.state_transition_validation: class: \Drupal\workbench_moderation\StateTransitionValidation arguments: ['@entity_type.manager', '@entity.query']