public function FilterEditForm::form in Entity Share 8.2
Same name and namespace in other branches
- 8.3 modules/entity_share_server/src/Form/FilterEditForm.php \Drupal\entity_share_server\Form\FilterEditForm::form()
- 8 modules/entity_share_server/src/Form/FilterEditForm.php \Drupal\entity_share_server\Form\FilterEditForm::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/ FilterEditForm.php, line 27
Class
- FilterEditForm
- Class FilterEditForm.
Namespace
Drupal\entity_share_server\FormCode
public function form(array $form, FormStateInterface $form_state) {
// Check if the filter exists.
if (!$this
->filterIdExists()) {
$this
->messenger()
->addError($this
->t('There is no filter with the ID @id in this channel', [
'@id' => $this
->getFilterId(),
]));
return [];
}
$form = parent::form($form, $form_state);
/** @var \Drupal\entity_share_server\Entity\ChannelInterface $channel */
$channel = $this->entity;
$channel_filters = $channel
->get('channel_filters');
$filter_id = $this
->getFilterId();
$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,
'#default_value' => $channel_filters[$filter_id]['path'],
];
$form['filter_id'] = [
'#type' => 'machine_name',
'#title' => $this
->t('ID'),
'#default_value' => $filter_id,
'#machine_name' => [
'source' => [
'path',
],
'exists' => [
$this,
'filterExists',
],
],
'#disabled' => TRUE,
];
$form['operator'] = [
'#type' => 'select',
'#title' => $this
->t('Operator'),
'#options' => OperatorsHelper::getOperatorOptions(),
'#empty_option' => $this
->t('Select an operator'),
'#default_value' => $channel_filters[$filter_id]['operator'],
'#required' => TRUE,
'#ajax' => [
'callback' => [
get_class($this),
'buildAjaxValueElement',
],
'effect' => 'fade',
'method' => 'replace',
'wrapper' => 'value-wrapper',
],
];
// 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'),
'#default_value' => isset($channel_filters[$filter_id]['memberof']) ? $channel_filters[$filter_id]['memberof'] : '',
];
return $form;
}