HubspotFormSelectWidget.php in Hubspot forms 8
File
src/Plugin/Field/FieldWidget/HubspotFormSelectWidget.php
View source
<?php
namespace Drupal\hubspot_forms\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\hubspot_forms\HubspotFormsCore;
class HubspotFormSelectWidget extends WidgetBase {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$form_id = isset($items[$delta]->form_id) ? $items[$delta]->form_id : '';
$HubspotFormsCore = new HubspotFormsCore();
$element += [
'#type' => 'select',
'#title' => $this
->t('Hubspot Form'),
'#options' => $HubspotFormsCore
->getFormIds(),
'#default_value' => $form_id,
'#required' => TRUE,
];
return [
'form_id' => $element,
];
}
}