ViewsReferenceWidget.php in Views Reference Field 8
File
src/Plugin/Field/FieldWidget/ViewsReferenceWidget.php
View source
<?php
namespace Drupal\viewsreference\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget;
class ViewsReferenceWidget extends EntityReferenceAutocompleteWidget {
use ViewsReferenceTrait;
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$test = [
'filled' => TRUE,
];
$element = $this
->fieldElement($element, $items, $delta, $test);
return $element;
}
public function errorElement(array $element, ConstraintViolationInterface $error, array $form, FormStateInterface $form_state) {
return isset($element['display_id']) ? $element['display_id'] : FALSE;
}
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
$values = parent::massageFormValues($values, $form, $form_state);
$values = $this
->massageValues($values, $form, $form_state);
return $values;
}
}