DummyWidget.php in Entity Browser 8.2
File
tests/modules/entity_browser_test/src/Plugin/EntityBrowser/Widget/DummyWidget.php
View source
<?php
namespace Drupal\entity_browser_test\Plugin\EntityBrowser\Widget;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Form\FormStateInterface;
use Drupal\entity_browser\WidgetBase;
class DummyWidget extends WidgetBase {
public $entity;
public function defaultConfiguration() {
return [
'text' => '',
] + parent::defaultConfiguration();
}
public function getForm(array &$original_form, FormStateInterface $form_state, array $additional_widget_parameters) {
return [
'#markup' => $this->configuration['text'],
'#parents' => [],
];
}
public function submit(array &$element, array &$form, FormStateInterface $form_state) {
$this
->selectEntities([
$this->entity,
], $form_state);
}
protected function prepareEntities(array $form, FormStateInterface $form_state) {
return $form_state
->getValue('dummy_entities', []);
}
public function access() {
if (\Drupal::state()
->get('eb_test_dummy_widget_access', TRUE)) {
$access = AccessResult::allowed();
$access
->addCacheContexts([
'eb_dummy',
]);
}
else {
$access = AccessResult::forbidden();
$access
->addCacheContexts([
'eb_dummy',
]);
}
return $access;
}
}
Classes
Name |
Description |
DummyWidget |
Dummy widget implementation for test purposes. |