1

I am trying to implement a ReadHandler on customer. Based on the cms module page read handler I did the following.

In my module etc/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\Framework\EntityManager\MetadataPool">
        <arguments>
            <argument name="metadata" xsi:type="array">
                <item name="Magento\Customer\Api\Data\CustomerInterface" xsi:type="array">
                    <item name="entityTableName" xsi:type="string">customer_entity</item>
                    <item name="identifierField" xsi:type="string">entity_id</item>
                </item>
            </argument>
        </arguments>
    </type>
    <type name="Magento\Framework\EntityManager\Operation\ExtensionPool">
        <arguments>
            <argument name="extensionActions" xsi:type="array">
                <item name="Magento\Customer\Api\Data\CustomerInterface" xsi:type="array">
                    <item name="read" xsi:type="array">
                        <item name="customerReader" xsi:type="string">MyCompany\MyModuleCore\Model\ResourceModel\Customer\Relation\Privacy\ReadHandler</item>
                    </item>
                </item>
            </argument>
        </arguments>
    </type>

    <type name="Magento\Framework\EntityManager\HydratorPool">
        <arguments>
            <argument name="hydrators" xsi:type="array">
                <item name="Magento\Customer\Api\Data\CustomerInterface" xsi:type="string">Magento\Framework\EntityManager\AbstractModelHydrator</item>
            </argument>
        </arguments>
    </type>

</config>

and in

MyCompany\MyModuleCore\Model\ResourceModel\Customer\Relation\Privacy\ReadHandler.php file:

use Magento\Customer\Model\Customer;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\EntityManager\Operation\ExtensionInterface;

class ReadHandler implements ExtensionInterface
{

    /**
     * @var MetadataPool
     */
    protected $metadataPool;

    /**
     * @var Customer
     */
    protected $resourceCustomer;

    public function __construct(
        MetadataPool $metadataPool,
        Customer $resourceCustomer
    )
    {
        $this->metadataPool = $metadataPool;
        $this->resourceCustomer = $resourceCustomer;
    }

    public function execute($entity, $arguments = [])
    {
        $this->metadataPool->getMetadata();
        return $entity;
    }


}

I've put breakpoints into the constructor and into the execute method but neither runs. Debugger works.

I've checked that the Model/Customer.php does not implements CustomerInterface but the Model/Data/Customer.php does. I've set breakpoint there and debugger stops there.

What do I missing?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.