You are here

public function EntityList::buildForm in Entity Update 8

Same name and namespace in other branches
  1. 2.0.x src/Form/EntityList.php \Drupal\entity_update\Form\EntityList::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/EntityList.php, line 32

Class

EntityList
Class EntityList.

Namespace

Drupal\entity_update\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = '', $start = '', $length = '') {
  $link_help = '/admin/help/entity_update';
  $form['messages']['about'] = [
    '#type' => 'markup',
    '#markup' => "Please refer to the <a href='{$link_help}'>Help page</a>.",
    '#prefix' => '<div>',
    '#suffix' => '</div>',
  ];
  $entity_types = EntityCheck::getEntityTypesList(NULL, FALSE);
  $form['filters'] = [
    '#type' => "fieldset",
    '#title' => "Filters",
    '#open' => TRUE,
  ];
  $options = [];
  foreach ($entity_types['#rows'] as $row) {
    $options[$row[0]] = $row[2];
  }
  $form['filters']['entity_type_id'] = [
    '#title' => 'The entity type',
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => $entity_type_id,
  ];
  $form['filters']['start'] = [
    '#title' => 'Start from',
    '#type' => 'number',
    '#default_value' => $start,
    '#step' => 1,
    '#min' => 0,
  ];
  $form['filters']['length'] = [
    '#title' => 'Maximum number of result',
    '#type' => 'number',
    '#default_value' => $length,
    '#step' => 1,
    '#min' => 1,
  ];
  $form['filters']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Show'),
  ];

  // Show Entities list.
  if ($entity_type_id) {
    $entities = EntityCheck::getEntityList($entity_type_id, $start, $length, FALSE);
    $form['result']['result'] = $entities;
  }
  return $form;
}