Skip to main content

Magento 2 issues with layouts

 Hi 

I came with new issue debugging if have xml tag not valid issue to find which file it is.

Some times we will get xml errors like 

1 exception(s): Exception #0 (Magento\Framework\Config\Dom\ValidationException):
Element 'referenceBlock', attribute 'remove': 'True' is not a valid value of the atomic
type 'xs:boolean'. Line: 1 Element 'referenceBlock', attribute 'remove': 'True' is not
a valid value of the atomic type 'xs:boolean'. Line: 2 Element 'referenceBlock', attribute
'remove': 'True' is not a valid value of the atomic type 'xs:boolean'. Line: 3


like this of errors we will get It's hard find which file it is if we did in any xml file we can easily locate if some done long days ago if got ticket to solve this is hard to find. Some will do in pages admin Layout Update XML section some one done core files based their flexible they will do but finding is hard so for this do below steps we will get error code based on that we can search ang solve it

more info that might help resolve this by identifying the file at fault.

Edit vendor/magento/framework/Config/Dom.php

Or it might be lib/internal/Magento/Framework/Config/Dom.php depending on your installation of Magento.


Find the public function _initDom($xml)

And add something like this before the normal validation check.

$verboseOutput = true;

if ($verboseOutput) {
if ($this->validationState->isValidationRequired() && $this->schema) {
$errors = $this->validateDomDocument($dom, $this->schema, $this->errorFormat);
if (count($errors)) {
var_dump($errors);
$matches = [];
preg_match("/Line: (\\d+)/", $errors[count($errors)-1], $matches);
$lineNumber = intval($matches[1]);
$lines = explode("\n", $xml);
echo "<h1>A validation error occured in an XML layout file</h1>";
$lineText = htmlentities($lines[$lineNumber-1]);
echo $lineText . "<br>";
echo "<pre>";
echo "grep -rnw ./app -e " . escapeshellarg(trim($lineText));
echo "</pre>";
die('Please grep or search files for the above and fix it as per Magento 2 validation.');
}
}
}

Before adding code :::

protected function _initDom($xml)
{
$dom = new \DOMDocument();
$useErrors = libxml_use_internal_errors(true);
$res = $dom->loadXML($xml);
if (!$res) {
$errors = self::getXmlErrors($this->errorFormat);
libxml_use_internal_errors($useErrors);
throw new \Magento\Framework\Config\Dom\ValidationException(implode("\n", $errors));
}
libxml_use_internal_errors($useErrors);
if ($this->validationState->isValidationRequired() && $this->schema) {
$errors = $this->validateDomDocument($dom, $this->schema, $this->errorFormat);
if (count($errors)) {
throw new \Magento\Framework\Config\Dom\ValidationException(implode("\n", $errors));
}
}
return $dom;
}


After Adding::

protected function _initDom($xml)
{
$dom = new \DOMDocument();
$useErrors = libxml_use_internal_errors(true);
$res = $dom->loadXML($xml);

$verboseOutput = true;
if ($verboseOutput) {
if ($this->validationState->isValidationRequired() && $this->schema) {
$errors = $this->validateDomDocument($dom, $this->schema, $this->errorFormat);
if (count($errors)) {
var_dump($errors);
$matches = [];
preg_match("/Line: (\\d+)/", $errors[count($errors)-1], $matches);
$lineNumber = intval($matches[1]);
$lines = explode("\n", $xml);
echo "<h1>A validation error occured in an XML layout file</h1>";
$lineText = htmlentities($lines[$lineNumber-1]);
echo $lineText . "<br>";
echo escapeshellarg(trim($lineText);
die('Please grep or search files for the above and fix it as per Magento 2 validation.');
}
}
}
if (!$res) {
$errors = self::getXmlErrors($this->errorFormat);
libxml_use_internal_errors($useErrors);
throw new \Magento\Framework\Config\Dom\ValidationException(implode("\n", $errors));
}
libxml_use_internal_errors($useErrors);
if ($this->validationState->isValidationRequired() && $this->schema) {
$errors = $this->validateDomDocument($dom, $this->schema, $this->errorFormat);
if (count($errors)) {
throw new \Magento\Framework\Config\Dom\ValidationException(implode("\n", $errors));
}
}
return $dom;
}

for me I got

<referenceBlock name="aheadworks.blog.recent.posts" remove="True" />

I removed remove true tag then it working it is added under cmspages 

After fixing please remove code and save 

And add something like this before the normal validation check.



Comments

Popular posts from this blog

magento 1 extension converted in to magento 2 process

Simple Install =================================== Download as a zip below link. unzip and upload it to your public_html or other rootdoc directory. https://github.com/magento/code-migration. login to your server via shell switch to the code-migration-develop directory by running following command   cd code-migration-develop Run command following command in root directory of this toolkit composer instal Before running the migration, the following directories need to be prepared: ===================================== * `<src>` - Directory that contains custom Magento 1.x code that is intended to be migrated. The code must follow the Magento 1.x directory structure.   Magento1.x core files must not be included. * `<dst>` - Empty directory for the toolkit to put the generated Magento 2 code to * `<m1>` - Directory that contains: * Vanilla Magento 1.x codebase, and * Custom Magento 1.x code same as...

Magento 2 product collection Filtering multi-select attribute values

  If you have multi-select attribute of product like below If you want filter value for this option Use below syntax to get product data: ->addAttributeToFilter('store_model', array('finset' => $params['store_model'])) finset key is used for multiselect attribute filter. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $products = $objectManager->get('Magento\Catalog\Model\Product')         ->getCollection()         ->addAttributeToSelect('*')         ->addAttributeToSelect('store_brand')         ->addAttributeToSelect('store_model')         ->addAttributeToSelect('store_year')         ->addAttributeToFilter('store_brand', array('finset' => $params['store_brand']))         ->addAttributeToFilter('store_model', array('finset' => $params['store_model']))         ->ad...

Magento Debug HEADERS ALREADY SENT error

When you  receiving the following error in  system.log file: app\code\core\Mage\Core\Controller\Response\Http.php:44  [1] \www.pawan.com\lib\Zend\Controller\Response\Abstract.php:727  [2]  \www.pawan.com\app\code\core\Mage\Core\Controller\Response\Http.php:75  [3]  \www.pawan.com\app\code\core\Mage\Core\Controller\Varien\Front.php:188  [4]  \www.pawan.com\app\code\core\Mage\Core\Model\App.php:304  [5]  \www.pawan.com\app\Mage.php:596  [6]  \www.pawan.com\index.php:81 if you have no idea what file is causing this. Here is the steps to debug. That error is thrown from Mage_Core_Controller_Response_Http -> sendHeaders(). This function calls the super class function that actually does the check to see whether or not headers have already been sent, Zend_Controller_Response_Abstract -> canSendHeaders(). The Zend_Controller_Response_Abstract class handles, among other things, sending response header...