Example #1
0
 /**
  * Creates a translated entity.
  */
 protected function createTranslatableEntity()
 {
     $this->entity = EntityTest::create();
     $this->entity->addTranslation('es', ['name' => 'name spanish']);
     $this->entity->addTranslation('fr', ['name' => 'name french']);
     $this->entity->save();
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // The revision timestamp will be updated when the revision is saved. Keep
     // the original one for the confirmation message.
     $this->entityRevision->setNewRevision();
     $this->entityRevision->isDefaultRevision(TRUE);
     if ($this->entityRevision instanceof EntityRevisionLogInterface) {
         if ($this->entityRevision instanceof TimestampedRevisionInterface) {
             $original_revision_timestamp = $this->entityRevision->getRevisionCreationTime();
             $this->entityRevision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
         } else {
             $this->entityRevision->revision_log = t('Copy of the revision');
         }
     }
     $this->entityRevision->save();
     $this->logger('content')->notice('@type: reverted %title revision %revision.', ['@type' => $this->entityRevision->bundle(), '%title' => $this->entityRevision->label(), '%revision' => $this->entityRevision->getRevisionId()]);
     drupal_set_message(t('@type %title has been reverted to the revision', ['@type' => $this->entityRevision->{$this->entityRevision->getEntityType()->getKey('bundle')}->entity->label(), '%title' => $this->entityRevision->label()]));
     $form_state->setRedirectUrl($this->entityRevision->urlInfo('version-history'));
 }
 /**
  * Save the entity.
  *
  * @param \Drupal\Core\Entity\ContentEntityInterface $entity
  *   The content entity.
  * @param array $old_destination_id_values
  *   An array of destination id values.
  *
  * @return array
  *   An array containing the entity id.
  */
 protected function save(ContentEntityInterface $entity, array $old_destination_id_values = array())
 {
     $entity->save();
     return array($entity->id());
 }
Example #4
0
 /**
  * @param string $correspondingFieldName
  *  Name of the field on the target entity which holds references back to the
  * referer that need corresponding.
  * @param $refererId
  *  Id of the referencing entity whose update has triggered this.
  * @param $referencedEntity
  *   The referenced entity that needs its corresponding field updating.
  */
 public function removeCorrespondingReference($correspondingFieldName, $refererId, ContentEntityInterface $referencedEntity)
 {
     $correspondingField = $referencedEntity->get($correspondingFieldName);
     $currentReferences = $correspondingField->getValue();
     $desiredReferences = $this->nested_array_diff([['target_id' => $refererId]], $currentReferences);
     $correspondingField->setValue($desiredReferences);
     $referencedEntity->save();
 }