I'm trying to extend customer address edit page, but it is throwing Error. For these I have written code as below.
composer.json
{
"name": "learning/module-contact",
"description": "Contact",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"magento/framework": "100.0.*",
"magento/module-ui": "100.0.*",
"magento/module-config": "100.0.*"
},
"type": "magento2-module",
"version": "1.0.0",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Learning\\Contact\\": ""
}
}
}
registration.php
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Learning_Contact',
__DIR__
);
module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Learning_Contact" setup_version="1.0.0">
</module>
</config>
di.xml
<?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\Block\Address\Edit">
<plugin name="contact-custom-module" type="Learning\Contact\Block\Address\Edit" sortOrder="0"/>
</type>-->
<preference for="Magento\Customer\Block\Address\Edit" type="Learning\Contact\Block\Address\Edit"/>
</config>
Edit.php
<?php
namespace Learning\Contact\Block\Address;
class Edit extends \Magento\Customer\Block\Address\Edit{
/**
* Registry
*
* @var \Magento\Framework\Registry
*/
protected $_registry;
public function __construct(\Magento\Framework\Registry $registry){
$this->_registry = $registry;
parent::__construct();
}
public function _toHtml() {
if ($this->getTemplate() == 'customer/address/edit.phtml') {
$htmlToInsertAfter = '<h2 class="legend">'. __('Address') .'</h2>';
$addressCandidatesHtml = $this->getLayout()->createBlock('contact/candidates')->setTemplate('custom.phtml');
$editHtml = parent::_toHtml();
return substr_replace($editHtml, $addressCandidatesHtml, strpos($editHtml, $htmlToInsertAfter)+strlen($htmlToInsertAfter),0);
}
return parent::_toHtml();
}
}
custom.phtml
<h1>Hi I'm here</h1>
Error : Object DOMDocument should be created
Is it correct procedure to extend customer address edit page?
Best Answer
composer.json
registration.php
module.xml
Edit.php