Created
April 4, 2018 08:43
-
-
Save quisse/10e2a5a90f8dc55f82f972efe138e3ad to your computer and use it in GitHub Desktop.
Proposal for adding a productAttribute handler in Magento 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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\Catalog\Helper\Output"> | |
<plugin name="OutputHelper" type="Vendor\Module\Plugin\OutputPlugin" sortOrder="1"/> | |
</type> | |
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\Module\Plugin; | |
use Magento\Catalog\Helper\Output; | |
class OutputPlugin { | |
public function beforeCollectHandlers(Output $outputHelper) { | |
$outputHelper->addHandler('productAttribute', $this); | |
} | |
public function productAttribute($helper, $value, $parameters) { | |
$attribute = $parameters['attribute']; | |
switch ($attribute) { | |
case 'attribute' : | |
$r = '<ul class="advice">' . implode("\n", $attribute) . '</ul>'; | |
break; | |
default: | |
$r = $value; | |
break; | |
} | |
return $r; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment