-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathFieldConfigSubscriber.php
51 lines (43 loc) · 1.42 KB
/
FieldConfigSubscriber.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Oro\Bundle\AkeneoBundle\EventSubscriber;
use Oro\Bundle\EntityConfigBundle\Attribute\Entity\AttributeFamily;
use Oro\Bundle\EntityConfigBundle\Event\Events;
use Oro\Bundle\EntityConfigBundle\Event\FieldConfigEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FieldConfigSubscriber implements EventSubscriberInterface
{
/** @var array */
private $configs = [
AttributeFamily::class => ['attributeGroups' => ['full' => true]],
];
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [
Events::CREATE_FIELD => 'updateFieldConfig',
Events::UPDATE_FIELD => 'updateFieldConfig',
];
}
/**
* Updates field config.
*/
public function updateFieldConfig(FieldConfigEvent $event)
{
if (empty($this->configs[$event->getClassName()][$event->getFieldName()])) {
return;
}
$configManager = $event->getConfigManager();
$provider = $configManager->getProvider('importexport');
if (!$provider) {
return;
}
$config = $provider->getConfig($event->getClassName(), $event->getFieldName());
$configs = $this->configs[$event->getClassName()][$event->getFieldName()];
foreach ($configs as $key => $value) {
$config->set($key, $value);
}
$configManager->persist($config);
}
}