public function unhandleEntity(array $metadata = array())
 {
     if (!empty($metadata['webform_validation']['processed'])) {
         $unresolver = new Unresolver($this->original_entity, false);
         $unresolver->unresolveDependencies($metadata['webform_validation']['rules'], 'webform_validation');
         $new_webform_validation = (array) $unresolver->unresolvedDefinition();
         // Delete the existing validation fields.
         webform_validation_node_delete($this->original_entity->definition);
         // Add the new validation fields.
         foreach ($new_webform_validation as $rule) {
             unset($rule['ruleid']);
             $rule['action'] = 'add';
             $rule['nid'] = $this->original_entity->id();
             $rule['rule_components'] = $rule['components'];
             webform_validation_rule_save($rule);
         }
     }
 }
Esempio n. 2
0
 public function unhandleEntity(array $metadata = array())
 {
     if (!empty($metadata['sitemap_definition'])) {
         // Unresolve the sitemap information.
         $unresolver = new Unresolver($this->original_entity, false);
         $unresolver->unresolveDependencies($metadata['sitemap_definition'], 'xmlsitemap');
         $new_sitemap = (array) $unresolver->unresolvedDefinition();
         unset($new_sitemap['id']);
         unset($new_sitemap['changefreq']);
         unset($new_sitemap['changecount']);
         unset($new_sitemap['lastmod']);
         // Get the existing sitemap link.
         $existing = xmlsitemap_link_load($this->original_entity->type(), $this->original_entity->id());
         // Overwrite the values in the existing if one already exists.
         if ($existing) {
             xmlsitemap_link_save(array_replace($existing, $new_sitemap));
         } else {
             xmlsitemap_link_save($new_sitemap);
         }
     }
 }
Esempio n. 3
0
 protected function applyRevision(Entity &$entity, $revision_payload)
 {
     global $user;
     // Preserve the original entity.
     $original_entity = clone $entity;
     // Apply changes to the entity.
     $entity->definition = (object) array_replace_recursive((array) $entity->definition, (array) $revision_payload['additions']);
     // Apply deletions to the entity.
     $deletions_definition = (array) $entity->definition;
     $keys_to_delete = array();
     $this->applyRevisionDeletions($deletions_definition, $revision_payload['deletions'], $keys_to_delete);
     $entity->definition = (object) $deletions_definition;
     // Run the beforeDependencies preparer.
     $preparer_registry = new PreparerRegistry();
     $preparer_registry->beforeDependencies($entity);
     // Revert references.
     $unresolver = new Unresolver($entity);
     $entity->definition = $unresolver->unresolvedDefinition();
     // Check to see if there were any errors reverting references.
     if ($errors = $unresolver->errors()) {
         $this->transaction->addErrors($errors);
         return false;
         // Stop processing this entity if there were errors.
     }
     // Unset the node VID and the user ID.
     $entity->definition->revision = true;
     if (isset($entity->definition->revision_uid)) {
         $user->uid = $entity->definition->revision_uid;
     } elseif (isset($entity->definition->uid)) {
         $user->uid = $entity->definition->uid;
     }
     // Get the old stuff for the node.
     $old_revision_information = array('uid' => $user->uid, 'vuuid' => $entity->vuuid());
     // Set unchanging properties to the node that was sent.
     $unchanging_properties = publisher_get_unchanging_properties($entity->type());
     foreach ($unchanging_properties as $property) {
         if (!isset($revision_payload['additions'][$property])) {
             continue;
         }
         $entity->definition->{$property} = $revision_payload['additions'][$property];
     }
     // Get the revision table for the entity.
     $entity_info = entity_get_info($entity->type());
     if (array_key_exists('revision table', $entity_info)) {
         $revision_table = $entity_info['revision table'];
         $revision_key = $entity_info['entity keys']['revision'];
         $revision_uuid_key = $entity_info['entity keys']['revision uuid'];
     }
     // Update the VID to an existing revision.
     if ($entity->supportsRevisions() && isset($revision_key)) {
         $this->setEntityRevisionID($entity->vuuid(), $entity);
     }
     // Run the preparers beforeSave.
     $preparer_registry->beforeSave($entity);
     // Run the entity handlers with the metadata.
     foreach (EntityHandlerRegistry::getEntityHandlers($entity) as $handler) {
         if (!$handler instanceof EntityHandlerBase) {
             continue;
         }
         $handler->entity =& $entity;
         $handler->original_entity = $original_entity;
         $handler->unhandleRevision($this->getEntityFromMetadata($entity->uuid()));
     }
     // Save the entity.
     try {
         $entity->save();
     } catch (\Exception $ex) {
         // ...and try to catch any exceptions thrown by this (sometimes, the exceptions still aren't caught).
         $this->transaction->addError($ex);
         return false;
     }
     if (isset($revision_table) && isset($revision_key)) {
         // Reset the UID and VUUID for the revision.
         $cloned_definition = clone $entity->definition;
         $cloned_definition->uid = $old_revision_information['uid'];
         $cloned_definition->{$revision_uuid_key} = $old_revision_information['vuuid'];
         drupal_write_record($revision_table, $cloned_definition, $revision_key);
         // Delete duplicate revisions that no longer apply.
         $this->checkForDuplicateRevisions($cloned_definition, $entity);
         // Reset the revision cache in the entity class.
         Entity::getLatestRevisionID($entity->id(), $entity->type(), true);
     }
     // Run the preparers afterSave events.
     $preparer_registry->afterSave($entity);
     return true;
 }