You are here

public function FilterAddForm::form in Entity Share 8

Same name and namespace in other branches
  1. 8.3 modules/entity_share_server/src/Form/FilterAddForm.php \Drupal\entity_share_server\Form\FilterAddForm::form()
  2. 8.2 modules/entity_share_server/src/Form/FilterAddForm.php \Drupal\entity_share_server\Form\FilterAddForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

modules/entity_share_server/src/Form/FilterAddForm.php, line 18

Class

FilterAddForm
Class FilterAddForm.

Namespace

Drupal\entity_share_server\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['#tree'] = TRUE;
  $form['path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Path'),
    '#description' => $this
      ->t('Enter the machine name of the field / property you want to filter on. You can reference field / property of a referenced entity. Example: uid.name for the name of the author.'),
    '#required' => TRUE,
  ];
  $form['filter_id'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t('ID'),
    '#machine_name' => [
      'source' => [
        'path',
      ],
      'exists' => [
        $this,
        'filterExists',
      ],
    ],
  ];
  $form['operator'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Operator'),
    '#options' => OperatorsHelper::getOperatorOptions(),
    '#empty_option' => $this
      ->t('Select an operator'),
    '#required' => TRUE,
    '#ajax' => [
      'callback' => [
        get_class($this),
        'buildAjaxValueElement',
      ],
      'wrapper' => 'value-wrapper',
      'method' => 'replace',
      'effect' => 'fade',
    ],
  ];

  // Container for the AJAX.
  $form['value_wrapper'] = [
    '#type' => 'container',
    // Force an id because otherwise default id is changed when using AJAX.
    '#attributes' => [
      'id' => 'value-wrapper',
    ],
  ];
  $this
    ->buildValueElement($form, $form_state);
  $form['memberof'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Parent group'),
    '#options' => $this
      ->getGroupOptions(),
    '#empty_option' => $this
      ->t('Select a group'),
  ];
  return $form;
}