Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EntitySnapshot.php
Go to the documentation of this file.
1 <?php
8 
11 
16 {
22  protected $snapshotData = [];
23 
27  protected $metadataPool;
28 
32  protected $attributeProvider;
33 
38  public function __construct(
41  ) {
42  $this->metadataPool = $metadataPool;
43  $this->attributeProvider = $attributeProvider;
44  }
45 
52  {
53  $metadata = $this->metadataPool->getMetadata($entityType);
54  $hydrator = $this->metadataPool->getHydrator($entityType);
55  $entityData = $hydrator->extract($entity);
56  $attributes = $this->attributeProvider->getAttributes($entityType);
57  $this->snapshotData[$entityType][$entityData[$metadata->getIdentifierField()]]
58  = array_intersect_key($entityData, $attributes);
59  }
60 
68  public function isModified($entityType, $entity)
69  {
70  $metadata = $this->metadataPool->getMetadata($entityType);
71  $hydrator = $this->metadataPool->getHydrator($entityType);
72  $entityData = $hydrator->extract($entity);
73  if (empty($entityData[$metadata->getIdentifierField()])) {
74  return true;
75  }
76  $identifier = $entityData[$metadata->getIdentifierField()];
77  if (!isset($this->snapshotData[$entityType][$identifier])) {
78  return true;
79  }
80  foreach ($this->snapshotData[$entityType][$identifier] as $field => $value) {
81  if (isset($entityData[$field]) && $entityData[$field] != $value) {
82  return true;
83  }
84  }
85  return false;
86  }
87 }
__construct(MetadataPool $metadataPool, AttributeProvider $attributeProvider)
$value
Definition: gender.phtml:16
$entity
Definition: element.phtml:22
$attributes
Definition: matrix.phtml:13