public function SearchEditForm::form in Entity Share 8.3
Same name and namespace in other branches
- 8.2 modules/entity_share_server/src/Form/SearchEditForm.php \Drupal\entity_share_server\Form\SearchEditForm::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/ SearchEditForm.php, line 26
Class
- SearchEditForm
- Form to edit a search on a channel.
Namespace
Drupal\entity_share_server\FormCode
public function form(array $form, FormStateInterface $form_state) {
// Check if the search exists.
if (!$this
->searchIdExists()) {
$this
->messenger()
->addError($this
->t('There is no search with the ID @id in this channel', [
'@id' => $this
->getsearchId(),
]));
return [];
}
$form = parent::form($form, $form_state);
/** @var \Drupal\entity_share_server\Entity\ChannelInterface $channel */
$channel = $this->entity;
$channel_searches = $channel
->get('channel_searches');
$search_id = $this
->getsearchId();
$form['path'] = [
'#type' => 'textfield',
'#title' => $this
->t('Path'),
'#description' => $this
->t('Enter the machine name of the field / property you want to be able to search in, on the client website. You can reference field / property of a referenced entity. Example: uid.name for the name of the author.'),
'#required' => TRUE,
'#default_value' => $channel_searches[$search_id]['path'],
];
$form['search_id'] = [
'#type' => 'machine_name',
'#title' => $this
->t('ID'),
'#default_value' => $search_id,
'#machine_name' => [
'source' => [
'path',
],
'exists' => [
$this,
'searchExists',
],
],
'#disabled' => TRUE,
];
$form['search_label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#default_value' => $channel_searches[$search_id]['label'],
'#required' => TRUE,
];
return $form;
}