Skip to content

Instantly share code, notes, and snippets.

@quisse
Created April 4, 2018 08:43
Show Gist options
  • Save quisse/10e2a5a90f8dc55f82f972efe138e3ad to your computer and use it in GitHub Desktop.
Save quisse/10e2a5a90f8dc55f82f972efe138e3ad to your computer and use it in GitHub Desktop.
Proposal for adding a productAttribute handler in Magento 2
<?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>
<?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