0

I have written a module to override vendor/magento/module-customer/Block/Form/Login/Login.php in app/code to change the page title. My override code is below:

<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace CoreEdits\LoginTitle\Block;

/**
* Customer login form block
*
* @author      Magento Core Team <core@magentocommerce.com>
*/
class Login extends \Magento\Customer\Block\Form\Login\Login
{
/**
 * @Override Title
 */
protected function _prepareLayout()
{
    $this->pageConfig->getTitle()->set(__('Customer Login - Test'));
    return parent::_prepareLayout();
}
}

EDIT: This is my di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<preference for="Magento\Customer\Block\Form\Login\Login" type="CoreEdits\LoginTitle\Block\Login"/>
</config>

However, when I run setup:upgrade the title remains the same. Is the above code correct?

  • Do you have etc/di.xml in your module? – Evgeny Levinsky Oct 30 '17 at 7:47
  • Yes, please check the edit – bondimedical Oct 30 '17 at 7:49
3

You need override \Magento\Customer\Block\Form\Login, not \Magento\Customer\Block\Form\Login\Login.

your_module_root/etc/di.xml

<preference for="Magento\Customer\Block\Form\Login" type="CoreEdits\LoginTitle\Block\Login" />

your_module_root/Block/Login.php

<?php

namespace CoreEdits\LoginTitle\Block;

class Login extends \Magento\Customer\Block\Form\Login
{
    protected function _prepareLayout()
    {
        $this->pageConfig->getTitle()->set(__('Customer Login - Test'));
    }
}

After override block class you need specify name of template in your layout:

your_theme_root/Magento_Customer/layout/customer_account_login.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_form_login" template="Magento_Customer::form/login.phtml" />
    </body>
</page>

Write me if you have any issues.

  • That doesn't work. Half the content on the page has now disappeared and title is still the same. I am pretty sure you need to override \Magento\Customer\Block\Form\Login\Login – bondimedical Oct 30 '17 at 8:54
  • Did you call setup:upgrade after file changes? – Evgeny Levinsky Oct 30 '17 at 8:56
  • Yes, thats when all the content on the page disappeared. – bondimedical Oct 30 '17 at 8:57
  • I updated my answer, check it, please – Evgeny Levinsky Oct 30 '17 at 9:10
  • 1
    Do your _prepareLayout method return parent::_prepareLayout()? In my answer this is not. Check, please – Evgeny Levinsky Oct 30 '17 at 10:00
2

create a customer_account_login.xml file to change title of customer login

For theme level,

app/design/frontend/{Packagename}/{themename}/Magento_Customer/layout/customer_account_login.xml

For module level,

app/code/{Package}/{Module}/view/frontend/layout/customer_account_login.xml

add below content in xml file

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="page.main.title">
           <action method="setPageTitle">
              <argument translate="true" name="title" xsi:type="string">Wholesale Customer Login</argument>
           </action>
        </referenceBlock>
    </body>
</page>

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.