/**
  * {@inheritdoc}
  */
 public static function processDefaultValue($default_value, ContentEntityInterface $entity, FieldDefinitionInterface $definition)
 {
     $default_value = parent::processDefaultValue($default_value, $entity, $definition);
     // Convert UUIDs to numeric IDs.
     $uuids = array();
     foreach ($default_value as $delta => $properties) {
         $uuids[$delta] = $properties['target_uuid'];
     }
     if ($uuids) {
         $entity_ids = \Drupal::entityQuery('taxonomy_term')->condition('uuid', $uuids, 'IN')->execute();
         $entities = \Drupal::entityManager()->getStorage('taxonomy_term')->loadMultiple($entity_ids);
         foreach ($entities as $id => $entity) {
             $entity_ids[$entity->uuid()] = $id;
         }
         foreach ($uuids as $delta => $uuid) {
             if (isset($entity_ids[$uuid])) {
                 $default_value[$delta]['target_id'] = $entity_ids[$uuid];
                 unset($default_value[$delta]['target_uuid']);
             } else {
                 unset($default_value[$delta]);
             }
         }
     }
     // Ensure we return consecutive deltas, in case we removed unknown UUIDs.
     $default_value = array_values($default_value);
     return $default_value;
 }
 /**
  * {@inheritdoc}
  */
 public function defaultValuesFormSubmit(array $element, array &$form, array &$form_state)
 {
     $default_value = parent::defaultValuesFormSubmit($element, $form, $form_state);
     // Convert numeric IDs to UUIDs to ensure config deployability.
     $ids = array();
     foreach ($default_value as $delta => $properties) {
         $ids[] = $properties['target_id'];
     }
     $entities = \Drupal::entityManager()->getStorage($this->getSetting('target_type'))->loadMultiple($ids);
     foreach ($default_value as $delta => $properties) {
         $uuid = $entities[$properties['target_id']]->uuid();
         // @todo Some entities do not have uuid. IE: Anonymous and admin user.
         //   Remove this special case once http://drupal.org/node/2050843
         //   has been fixed.
         if (!$uuid) {
             $uuid = $properties['target_id'] == '0' ? 'anonymous' : 'administrator';
         }
         unset($default_value[$delta]['target_id']);
         $default_value[$delta]['target_uuid'] = $uuid;
     }
     return $default_value;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function deleteRevision()
 {
     parent::deleteRevision();
     $entity = $this->getEntity();
     // Decrement the file usage by 1.
     foreach ($this->referencedEntities() as $file) {
         \Drupal::service('file.usage')->delete($file, 'file', $entity->getEntityTypeId(), $entity->id());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     $this->computeModerationFieldItemList();
     return parent::getIterator();
 }
 /**
  * {@inheritdoc}
  */
 public function defaultValuesFormSubmit(array $element, array &$form, FormStateInterface $form_state)
 {
     $default_value = parent::defaultValuesFormSubmit($element, $form, $form_state);
     // Convert numeric IDs to UUIDs to ensure config deployability.
     $ids = array();
     foreach ($default_value as $delta => $properties) {
         $ids[] = $properties['target_revision_id'];
     }
     $entities = array();
     foreach ($ids as $id) {
         $entities[$id] = \Drupal::entityManager()->getStorage($this->getSetting('target_type'))->loadRevision($id);
     }
     foreach ($default_value as $delta => $properties) {
         $default_value[$delta] = array('target_uuid' => $entities[$properties['target_revision_id']]->uuid(), 'target_revision_id' => $properties['target_revision_id']);
     }
     return $default_value;
 }