View source
<?php
namespace Drupal\entity_browser_test\Plugin\EntityBrowser\Widget;
use Drupal\Core\Form\FormStateInterface;
use Drupal\entity_browser\Element\EntityBrowserPagerElement;
use Drupal\entity_browser\WidgetBase;
class PagerTestWidget 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['message'] = [
'#markup' => $this
->t('Current page reported by the element is: @page.', [
'@page' => EntityBrowserPagerElement::getCurrentPage($form_state),
]),
];
$form['first'] = [
'#type' => 'submit',
'#value' => $this
->t('First page'),
'#submit' => [
[
static::class,
'submitFirst',
],
],
];
$form['last'] = [
'#type' => 'submit',
'#value' => $this
->t('Last page'),
'#submit' => [
[
static::class,
'submitLast',
],
],
];
$form['pager_eb'] = [
'#type' => 'entity_browser_pager',
'#total_pages' => 4,
];
return $form;
}
public function submitFirst(array &$form, FormStateInterface $form_state) {
EntityBrowserPagerElement::setCurrentPage($form_state);
$form_state
->setRebuild();
}
public function submitLast(array &$form, FormStateInterface $form_state) {
EntityBrowserPagerElement::setCurrentPage($form_state, 4);
$form_state
->setRebuild();
}
protected function prepareEntities(array $form, FormStateInterface $form_state) {
}
}