Skip to content

Commit 5b57200

Browse files
committed
B2B-2259: customAttributeMetadata GraphQl query has no cache identity
1 parent 5877921 commit 5b57200

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\EavGraphQl\Plugin\Eav;
9+
10+
use Magento\Eav\Model\Entity\Attribute;
11+
use Magento\Eav\Model\Entity\Attribute as EavAttribute;
12+
use Magento\Framework\DataObject\IdentityInterface;
13+
use Magento\Framework\Event\ManagerInterface;
14+
15+
/**
16+
* Currency plugin triggers clean page cache and provides currency cache identities
17+
*/
18+
class AttributePlugin implements IdentityInterface
19+
{
20+
/**
21+
* Application Event Dispatcher
22+
*
23+
* @var ManagerInterface
24+
*/
25+
private $eventManager;
26+
27+
/**
28+
* @var array
29+
*/
30+
private $identities = [];
31+
32+
/**
33+
* @param ManagerInterface $eventManager
34+
*/
35+
public function __construct(ManagerInterface $eventManager)
36+
{
37+
$this->eventManager = $eventManager;
38+
}
39+
40+
/**
41+
* Clean cache by relevant tags.
42+
*
43+
* @param Attribute $subject
44+
* @param Attribute $result
45+
* @return Attribute
46+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
47+
*/
48+
public function afterSave(
49+
Attribute $subject,
50+
Attribute $result
51+
): Attribute
52+
{
53+
$this->identities[] = sprintf(
54+
"%s_%s",
55+
EavAttribute::CACHE_TAG,
56+
$subject->getAttributeCode()
57+
);
58+
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this]);
59+
return $result;
60+
}
61+
62+
public function getIdentities()
63+
{
64+
return $this->identities;
65+
}
66+
}

0 commit comments

Comments
 (0)