diff --git a/quick_node_clone.module b/quick_node_clone.module index 21236991e59614516d668e83a0adb527ef951bac..c67f349cb384fdc1f95d9f7b0941741f47fc3386 100644 --- a/quick_node_clone.module +++ b/quick_node_clone.module @@ -6,8 +6,10 @@ */ use Drupal\Component\Utility\Html; +use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\group\Entity\GroupContent; @@ -19,7 +21,6 @@ function quick_node_clone_entity_type_build(array &$entity_types) { if (isset($entity_types['node'])) { $entity_types['node']->setFormClass('quick_node_clone', 'Drupal\quick_node_clone\Form\QuickNodeCloneNodeForm'); } - } /** @@ -70,6 +71,35 @@ function quick_node_clone_help($route_name, RouteMatchInterface $route_match) { return NULL; } +/** + * Implements hook_form_alter(). + */ +function quick_node_clone_form_alter(&$form, FormStateInterface $form_state, $form_id) { + if (!array_key_exists('footer', $form)) { + return; + } + + // Check the operation set on the form is 'quick_node_clone'. + $form_object = $form_state->getFormObject(); + if (!$form_object instanceof ContentEntityFormInterface) { + return; + } + if ($form_object->getOperation() !== 'quick_node_clone') { + return; + } + + // Check that the content entity being cloned is moderated. + if (!\Drupal::moduleHandler()->moduleExists('content_moderation')) { + return; + } + $moderation_info = \Drupal::service('content_moderation.moderation_information'); + if (!$moderation_info->isModeratedEntity($form_object->getEntity())) { + return; + } + + $form['moderation_state']['#group'] = 'footer'; +} + /** * Determine if the current user has permission to clone a specified node. *