MultipleSubmitTestWidget.php in Entity Browser 8
File
tests/modules/entity_browser_test/src/Plugin/EntityBrowser/Widget/MultipleSubmitTestWidget.php
View source
<?php
namespace Drupal\entity_browser_test\Plugin\EntityBrowser\Widget;
use Drupal\Core\Form\FormStateInterface;
use Drupal\entity_browser\WidgetBase;
class MultipleSubmitTestWidget extends WidgetBase {
public $entity;
public function getForm(array &$original_form, FormStateInterface $form_state, array $additional_widget_parameters) {
$form = parent::getForm($original_form, $form_state, $additional_widget_parameters);
$form['submit_second'] = [
'#type' => 'submit',
'#value' => $this
->t('Second submit button'),
];
return $form;
}
protected function prepareEntities(array $form, FormStateInterface $form_state) {
return $form_state
->getValue('dummy_entities', []);
}
public function submit(array &$element, array &$form, FormStateInterface $form_state) {
if ($this->entity) {
$this
->selectEntities([
$this->entity,
], $form_state);
}
}
}