7 use Drupal\Core\Entity\EntityInterface;
9 use Drupal\node\Entity\Node;
40 $this->validate($entity);
41 $this->node = $entity;
48 return $this->node->getCacheContexts();
55 $cacheTags = $this->node->getCacheTags();
63 return $this->node->getCacheMaxAge();
69 private function fix() {
71 $this->saveRawMetadata();
79 return $this->node->getChangedTime();
88 return $this->node->uuid();
96 if (isset($this->node->rawMetadata)) {
97 return json_decode($this->node->rawMetadata);
106 return $this->node->get(
'field_data_type')->value;
114 return json_decode($this->node->get(
'field_json_metadata')->getString());
122 $this->node->set(
'field_json_metadata', json_encode($metadata));
130 $this->node->set(
'uuid', $identifier);
138 $this->node->set(
'title', $title);
145 return $this->node->isNew();
151 private function validate(EntityInterface $entity) {
152 if (!($entity instanceof Node)) {
156 if ($entity->bundle() !=
"data") {
157 throw new DataNodeLifeCycleEntityValidationException(
"We only work with data nodes.");
164 private function fixDataType() {
165 if (empty($this->node->get(
'field_data_type')->getString())) {
166 $this->node->set(
'field_data_type',
'dataset');
175 $schemaId = $this->node->get(
'field_data_type')->getString();
182 private function saveRawMetadata() {
184 if (!isset($this->node->rawMetadata)) {
185 $raw = $this->node->get(
'field_json_metadata')->value;
186 $this->node->rawMetadata = $raw;
194 if (isset($this->node->original)) {
195 return new Data($this->node->original);