Example #1
0
 /**
  * {@inheritdoc}
  */
 public function toArray()
 {
     if (!isset($this->entity)) {
         throw new MissingDataException('Unable to get property values as no entity has been provided.');
     }
     return $this->entity->toArray();
 }
 /**
  * Returns the form action value when submitting a new translation.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity being tested.
  * @param string $langcode
  *   Language code for the form.
  *
  * @return string
  *   Name of the button to hit.
  */
 protected function getFormSubmitActionForNewTranslation(EntityInterface $entity, $langcode)
 {
     $entity->addTranslation($langcode, $entity->toArray());
     return $this->getFormSubmitAction($entity, $langcode);
 }
Example #3
0
 /**
  * Maps from an entity object to the storage record.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity object.
  *
  * @return array
  *   The record to store.
  */
 protected function mapToStorageRecord(EntityInterface $entity)
 {
     return $entity->toArray();
 }
 /**
  * {@inheritdoc}
  */
 protected function doSave($id, EntityInterface $entity)
 {
     $is_new = $entity->isNew();
     // Save the entity data in the key value store.
     $this->keyValueStore->set($entity->id(), $entity->toArray());
     // If this is a rename, delete the original entity.
     if ($this->has($id, $entity) && $id !== $entity->id()) {
         $this->keyValueStore->delete($id);
     }
     return $is_new ? SAVED_NEW : SAVED_UPDATED;
 }
 /**
  * {@inheritdoc}
  */
 protected function doSave($id, EntityInterface $entity)
 {
     $is_new = $entity->isNew();
     $prefix = $this->getConfigPrefix();
     if ($id !== $entity->id()) {
         // Renaming a config object needs to cater for:
         // - Storage needs to access the original object.
         // - The object needs to be renamed/copied in ConfigFactory and reloaded.
         // - All instances of the object need to be renamed.
         $config = $this->configFactory->rename($prefix . $id, $prefix . $entity->id());
     } else {
         $config = $this->configFactory->get($prefix . $id);
     }
     // Retrieve the desired properties and set them in config.
     foreach ($entity->toArray() as $key => $value) {
         $config->set($key, $value);
     }
     $config->save();
     return $is_new ? SAVED_NEW : SAVED_UPDATED;
 }