Skip to content

Commit

Permalink
HPC-9060: Fix feature that redirects to original publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
berliner committed Jul 6, 2023
1 parent 9451d88 commit b1dbe39
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 0 additions & 1 deletion html/modules/custom/ncms_publisher/ncms_publisher.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ description: 'Manage publishers that integrate with the HPC Content Module.'
package: HPC Content Module
core_version_requirement: ^9.3 || ^10
dependencies:
- ncms_ui:ncms_ui
- csp:csp
3 changes: 2 additions & 1 deletion html/modules/custom/ncms_publisher/ncms_publisher.module
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function ncms_publisher_form_node_form_alter(&$form, FormStateInterface $form_st
}

foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
$action_type = $form['actions'][$action]['#type'] ?? NULL;
if ($action != 'preview' && $action_type === 'submit') {
$form['actions'][$action]['#submit'][] = 'ncms_publisher_content_base_edit_form_submit';
}
}
Expand Down
2 changes: 1 addition & 1 deletion html/modules/custom/ncms_ui/ncms_ui.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
arguments: ['@entity_type.manager', '@current_user', '@tempstore.private', '@plugin.manager.views.join']
ncms_ui.content_base_form_alter:
class: Drupal\ncms_ui\Form\ContentBaseFormAlter
arguments: ['@request_stack', '@entity_type.manager', '@ncms_ui.content_space.manager', '@messenger', '@form_builder']
arguments: ['@request_stack', '@entity_type.manager', '@ncms_ui.content_space.manager', '@messenger', '@form_builder', '@ncms_publisher.publisher.manager']
ncms_ui.revision_overview_form_alter:
class: Drupal\ncms_ui\Form\RevisionOverviewFormAlter
arguments: ['@entity_type.manager', '@current_user', '@current_route_match', '@renderer', '@date.formatter', '@pager.manager']
Expand Down
18 changes: 15 additions & 3 deletions html/modules/custom/ncms_ui/src/Form/ContentBaseFormAlter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\ncms_publisher\PublisherManager;
use Drupal\ncms_ui\ContentSpaceManager;
use Drupal\ncms_ui\Entity\Content\ContentBase;
use Drupal\node\NodeInterface;
Expand Down Expand Up @@ -63,6 +64,13 @@ class ContentBaseFormAlter {
*/
protected $formBuilder;

/**
* The publisher manager service.
*
* @var \Drupal\ncms_publisher\PublisherManager
*/
protected $publisherManager;

/**
* Constructor.
*
Expand All @@ -76,13 +84,16 @@ class ContentBaseFormAlter {
* The messenger service.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder service.
* @param \Drupal\ncms_publisher\PublisherManager $publisher_manager
* The publisher manager service.
*/
public function __construct(RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, ContentSpaceManager $content_manager, MessengerInterface $messenger, FormBuilderInterface $form_builder) {
public function __construct(RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, ContentSpaceManager $content_manager, MessengerInterface $messenger, FormBuilderInterface $form_builder, PublisherManager $publisher_manager) {
$this->requestStack = $request_stack;
$this->entityTypeManager = $entity_type_manager;
$this->contentSpaceManager = $content_manager;
$this->messenger = $messenger;
$this->formBuilder = $form_builder;
$this->publisherManager = $publisher_manager;
}

/**
Expand Down Expand Up @@ -281,8 +292,9 @@ public function ajaxConfirm(array &$form, FormStateInterface $form_state) {
// Submit the form.
$this->submitForm($form, $form_state, TRUE);

// Go back to the backend listings page.
$response->addCommand(new RedirectCommand($updated_entity->getOverviewUrl()->toString()));
// Go back to the publisher or to the backend listings page.
$redirect_url = $this->publisherManager->getCurrentRedirectUrl() ?? $updated_entity->getOverviewUrl()->toString();
$response->addCommand(new RedirectCommand($redirect_url));
}
}

Expand Down

0 comments on commit b1dbe39

Please sign in to comment.