2

Today I had to create new controller, checking something while registering (ajax one). But every try of reaching it ends up in login page. I have found plugin vendor/magento/module-customer/Controller/Plugin/Account.php:29 which has some empty property allowedActions. Is it blocking from dispatching my action? Is it any way to omit that/add my action to that array?

Does it comes along with vendor/magento/module-customer/etc/frontend/sections.xml?

2

You can add to this list using di.xml. This because the plugin expects an array of allowed actions to passed into the constructor (which is defined in di.xml).

Take a look:

<?php
...
class Account
{
...
    public function __construct(
        Session $customerSession,
        array $allowedActions = []
    ) {
        $this->session = $customerSession;
        $this->allowedActions = $allowedActions;
    }
...
}

In the customer module take a look at etc/frontend/di.xml. You'll find the following definition:

<type name="Magento\Customer\Controller\Plugin\Account">
    <arguments>
        <argument name="allowedActions" xsi:type="array">
            <item name="create" xsi:type="string">create</item>
            <item name="login" xsi:type="string">login</item>
            <item name="logoutsuccess" xsi:type="string">logoutsuccess</item>
            <item name="forgotpassword" xsi:type="string">forgotpassword</item>
            <item name="forgotpasswordpost" xsi:type="string">forgotpasswordpost</item>
            <item name="resetpassword" xsi:type="string">resetpassword</item>
            <item name="resetpasswordpost" xsi:type="string">resetpasswordpost</item>
            <item name="confirm" xsi:type="string">confirm</item>
            <item name="confirmation" xsi:type="string">confirmation</item>
            <item name="createpassword" xsi:type="string">createpassword</item>
            <item name="createpost" xsi:type="string">createpost</item>
            <item name="loginpost" xsi:type="string">loginpost</item>
        </argument>
    </arguments>
</type>

So, what you can do is create your own etc/frontend/di.xml, and add your action to this array. That would look a little like this:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Customer\Controller\Plugin\Account">
        <arguments>
            <argument name="allowedActions" xsi:type="array">
                <item name="[myAction]" xsi:type="string">[myAction]</item>
            </argument>
        </arguments>
    </type>
</config>

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.