0

I'm trying to add a link next to the logged in user dropdown menu. Apparently the "Sign In or" part of "Sign In or Create an account" is not removed after logging in, but simply hidden.

When I add a custom link, the "Sign Out or" text becomes visible:

Example

Here is the generated html where the top link shows up in the dropdown after logging in, the bottom link is the login link that is usually shown when not logged in but now invisible.

<li class="authorization-link" data-label="or">
    <a href="http://localhost.test/customer/account/logout/" data-post='{"action":"http:\/\/localhost\/customer\/account\/logout\/","data":{"uenc":"aHR0cDovL3ZpZXRzZW5nby50ZXN0L2N1c3RvbWVyL2FjY291bnQv"}}'>
        Sign Out    </a>
</li>
</ul>        </div>
            </li>
<li class="authorization-link" data-label="or">
    <a href="http://localhost.test/customer/account/logout/" data-post='{"action":"http:\/\/localhost.test\/customer\/account\/logout\/","data":{"uenc":"aHR0cDovL3ZpZXRzZW5nby50ZXN0L2N1c3RvbWVyL2FjY291bnQv"}}'>
        Sign Out    </a>
</li>

After adding my custom link the generated html looks like this, and the "Sign Out or" text is visible next to my custom link.

<li class="authorization-link" data-label="or">
    <a href="http://localhost.test/customer/account/logout/" data-post='{"action":"http:\/\/localhost\/customer\/account\/logout\/","data":{"uenc":"aHR0cDovL3ZpZXRzZW5nby50ZXN0L2N1c3RvbWVyL2FjY291bnQv"}}'>
        Sign Out    </a>
</li>
</ul>        </div>
            </li>
<li><a href='/partner-portal'>Partner Portal</a> </li><li class="authorization-link" data-label="or">
    <a href="http://localhost.test/customer/account/logout/" data-post='{"action":"http:\/\/localhost.test\/customer\/account\/logout\/","data":{"uenc":"aHR0cDovL3ZpZXRzZW5nby50ZXN0L2N1c3RvbWVyL2FjY291bnQv"}}'>
        Sign Out    </a>
</li>

My App\Code\Company\Module\view\frontend\layout\default.xml file looks like this:

<?xml version="1.0"?>
<body>
    <referenceBlock name="header.links">
        <block class="Company\Module\Block\Portal\PortalLink" name="partner_portal">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Partner Portal</argument>
            </arguments>
        </block>
    </referenceBlock>
</body>

And my link class:

class PortalLink extends Link {
    protected $_session;

    public function __construct(Context $context, Session $session, array $data = []) {
        parent::__construct($context, $data);
        $this->_session = $session;
    }

    public function getHref() {
        return "/partner-portal";
    }

    protected function _toHtml() {
        if ($this->_session->getCustomerGroupId() == 3) {
            return parent::_toHtml();
        }

        return '';
    }
}

I tried editing the sign out link to return nothing when the user is logged in but that also removes the sign out link from the dropdown. I'd also rather not change anything in the Magento code because I'd like to be able to install my module on a clean install.

0

I managed to fix it by adding after="-" to my block in default.xml, which places it behind the authorization-link:

<?xml version="1.0"?>
<body>
    <referenceBlock name="header.links">
        <block class="Company\Module\Block\Portal\PortalLink" name="partner_portal" after="-">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Partner Portal</argument>
            </arguments>
        </block>
    </referenceBlock>
</body>
| improve this answer | |

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.