Possibility to set a message after redirect

Created on 12 October 2023, over 1 year ago
Updated 11 January 2024, about 1 year ago

Hello, and thanks for the module!

I just updated from 1.x to the newest 2.x (2.0.0-alpha3) and didn't understand what happened to the old "Message after redirection" form element? I can't find it anywhere and when I compare the code of the old version to the new version, a lot of the old code about the message is gone now?
I tried to look into some issues but didn't yet find anything where this change would have been discussed. The module page and the readme file still has the part about the redirect message:
"Current features
...a message that can be displayed to the user after redirection."

  • Did I miss something, or did I do a mistake when I updated the module?
  • Should I use the 1.x version if I want to have that message feature now, or do I need to use some other module?
  • Is the message feature coming back one day?

Thanks for any help!

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇫🇮Finland hartsak

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @hartsak
  • Assigned to rohan_singh
  • 🇷🇺Russia walkingdexter

    Hello, @hartsak!

    The message feature was removed for a reason - it's difficult to cover all possible use cases. In my opinion, this feature should be at the custom code level. I'm planning to add an event or hook before the redirect in 2.x, so that any desired behavior can be implemented. Until it's done, I recommend to use 1.x if it suits your requirements. The 2.x version has some nice new features (but they are not finalized yet) and if you need them you can implement a patch that returns the message feature.

  • 🇫🇮Finland hartsak

    Thank you for the quick reply @WalkingDexter !

    I'm probably going to re-think if I really need the message feature in the future. In the meantime, I will continue using the 1.x version and see if I'm able to patch it with the D10 patch from here:
    https://www.drupal.org/project/content_translation_redirect/issues/3369274 📌 Automated Drupal 10 compatibility fixes Closed: won't fix

    Great work with the module so far and have a nice weekend!

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India rohan_singh India

    Hi @WalkingDexter, I have added a patch to add the message after the module redirects to the requested page. Do let me know if I can help in any other way.

  • 🇷🇺Russia walkingdexter

    Example:

    custom.services.yml

    services:
      custom.event_subscriber:
        class: Drupal\custom\EventSubscriber\CustomEventSubscriber
        arguments: ['@messenger']
        tags:
          - { name: event_subscriber }
    

    src/EventSubscriber/CustomEventSubscriber.php

    <?php
    
    namespace Drupal\custom\EventSubscriber;
    
    use Drupal\content_translation_redirect\ContentTranslationRedirectEvents;
    use Drupal\content_translation_redirect\Event\ContentTranslationRedirectEvent;
    use Drupal\Core\Messenger\MessengerInterface;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    /**
     * Custom event subscriber.
     */
    class CustomEventSubscriber implements EventSubscriberInterface {
    
      /**
       * The messenger.
       *
       * @var \Drupal\Core\Messenger\MessengerInterface
       */
      protected $messenger;
    
      /**
       * CustomEventSubscriber constructor.
       *
       * @param \Drupal\Core\Messenger\MessengerInterface $messenger
       *   The messenger.
       */
      public function __construct(MessengerInterface $messenger) {
        $this->messenger = $messenger;
      }
    
      /**
       * Handles the content translation redirect.
       *
       * @param \Drupal\content_translation_redirect\Event\ContentTranslationRedirectEvent $event
       *   The event to process.
       */
      public function onRedirect(ContentTranslationRedirectEvent $event): void {
        $this->messenger->addStatus('Your message is here');
      }
    
      /**
       * {@inheritdoc}
       */
      public static function getSubscribedEvents(): array {
        $events[ContentTranslationRedirectEvents::REDIRECT][] = ['onRedirect'];
        return $events;
      }
    
    }
    
  • Issue was unassigned.
  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024