3

Anyone noticed that if you observe the event controller_action_predispatch in Magento 2.4.4

public function execute(Observer $observer)
{
    $request = $observer->getEvent()->getRequest();
    $fullActionName = $request->getFullActionName();
    // $fullActionName gives __ value 
    // for CMS & Category pages (M2.4.4)
    // ...    
}

👉 fullActionName always gives __ (double underscores) for CMS & category pages

Bug or Feature? And how to get the correct fullActionName?

Also, the value is __ for the following

  • Event for controller_front_send_response_before
  • Plugin for Magento\Framework\App\FrontControllerInterface::beforeDispatch()

[UPDATED]
This still gives the same __ value for CMS & Category pages:

/** @var \Magento\Framework\App\ActionInterface $action */
$action  = $observer->getEvent()->getData('controller_action');
if ($action instanceof \Magento\Framework\App\Action\Forward) {
    return $this;
}
$request = $observer->getEvent()->getRequest();
$fullActionName = $request->getFullActionName();
4
  • Confirmed the issue on CMS pages and category pages.
    – Tu Van
    Jun 8 at 13:02
  • I might say something dumb but...won't the result always be cms_index_index for cms page ? Only the url will change but the action will be the same.
    – Claims
    Jun 8 at 14:21
  • cms_page_view or cms_index_index is what's expected for CMS pages, but it's returning ___
    – MagePsycho
    Jun 8 at 15:56
  • What is $action instance you have ? Maybe is it a Redirect one? Jun 9 at 9:43

1 Answer 1

1

For those kind of pages the event controller_action_predispatch called 2 times

First time for \Magento\Framework\App\Action\Forward and route, controller and action are empty

Second time for \Magento\Cms\Controller\Page\View (for CMS) and route, controller and action are properly filled and you can use fullActionName method from request

You can check controller action instance in observer with following code

/** @var \Magento\Framework\App\ActionInterface $action */
$action  = $observer->getEvent()->getData('controller_action');

Just do nothing if $action is instance of \Magento\Framework\App\Action\Forward

[Added]

For understand the reason you can check CMS router logic in \Magento\Cms\Controller\Router. The method match populate request and returns \Magento\Framework\App\Action\Forward controller action instance for forward to correct end controller action

1
  • This is still giving the __ value (see my updated post)
    – MagePsycho
    Jun 9 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.