You are here

public static function EntityBrowserPagerElement::processEntityBrowserPager in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 src/Element/EntityBrowserPagerElement.php \Drupal\entity_browser\Element\EntityBrowserPagerElement::processEntityBrowserPager()

Process Entity browser pager element.

File

src/Element/EntityBrowserPagerElement.php, line 56

Class

EntityBrowserPagerElement
Provides an Entity Browser pager form element.

Namespace

Drupal\entity_browser\Element

Code

public static function processEntityBrowserPager(&$element, FormStateInterface $form_state, &$complete_form) {
  $page = static::getCurrentPage($form_state);
  $element['previous'] = [
    '#type' => 'submit',
    '#submit' => [
      [
        static::class,
        'submitPager',
      ],
    ],
    '#value' => t('‹ Previous'),
    '#name' => 'prev_page',
    '#disabled' => $page === 1,
    '#attributes' => [
      'class' => [
        'prev',
      ],
    ],
    '#limit_validation_errors' => [
      array_merge($element['#parents'], [
        'previous',
      ]),
    ],
  ];
  $element['current'] = [
    '#type' => 'html_tag',
    '#tag' => 'span',
    '#value' => t('Page @page', [
      '@page' => $page,
    ]),
    '#attributes' => [
      'class' => [
        'current',
      ],
    ],
  ];
  $element['next'] = [
    '#type' => 'submit',
    '#submit' => [
      [
        static::class,
        'submitPager',
      ],
    ],
    '#value' => t('Next ›'),
    '#name' => 'next_page',
    '#disabled' => $element['#total_pages'] == $page,
    '#attributes' => [
      'class' => [
        'next',
      ],
    ],
    '#limit_validation_errors' => [
      array_merge($element['#parents'], [
        'next',
      ]),
    ],
  ];
  return $element;
}