Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / entity_reference_revisions / src / Plugin / Field / FieldWidget / EntityReferenceRevisionsAutocompleteWidget.php
1 <?php
2
3 namespace Drupal\entity_reference_revisions\Plugin\Field\FieldWidget;
4
5 use Drupal\Core\Entity\Entity;
6 use Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget;
7 use Drupal\Core\Form\FormStateInterface;
8
9 /**
10  * Plugin implementation of the 'entity_reference_autocomplete' widget.
11  *
12  * @FieldWidget(
13  *   id = "entity_reference_revisions_autocomplete",
14  *   label = @Translation("Autocomplete"),
15  *   description = @Translation("An autocomplete text field."),
16  *   field_types = {
17  *     "entity_reference_revisions"
18  *   }
19  * )
20  */
21 class EntityReferenceRevisionsAutocompleteWidget extends EntityReferenceAutocompleteWidget {
22
23   /**
24    * {@inheritdoc}
25    */
26   public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
27     $entity_type = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('target_type');
28     foreach ($values as $key => $value) {
29       if($value['target_id']) {
30         $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($value['target_id']);
31         // Add the current revision ID.
32         $values[$key]['target_revision_id'] = $entity->getRevisionId();
33       }
34       // The entity_autocomplete form element returns an array when an entity
35       // was "autocreated", so we need to move it up a level.
36       if (is_array($value['target_id'])) {
37         unset($values[$key]['target_id']);
38         $values[$key] += $value['target_id'];
39       }
40     }
41     return $values;
42   }
43
44 }