improvements-2.x-dev/modules/improvements_views/src/Plugin/Field/FieldWidget/ViewsWidget.php
modules/improvements_views/src/Plugin/Field/FieldWidget/ViewsWidget.php
<?php namespace Drupal\improvements_views\Plugin\Field\FieldWidget; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\views\Views; /** * @FieldWidget( * id = "views_widget", * label = @Translation("Views"), * field_types = { * "views", * }, * ) */ class ViewsWidget extends WidgetBase { /** * {@inheritDoc} */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state): array { $element += [ '#type' => 'select', '#options' => Views::getViewsAsOptions(FALSE, 'enabled', NULL, TRUE, TRUE), '#default_value' => $items[$delta]->value ?? NULL, ]; return [ 'value' => $element, ]; } }