public function SortEditForm::form in Entity Share 8
Same name and namespace in other branches
- 8.3 modules/entity_share_server/src/Form/SortEditForm.php \Drupal\entity_share_server\Form\SortEditForm::form()
- 8.2 modules/entity_share_server/src/Form/SortEditForm.php \Drupal\entity_share_server\Form\SortEditForm::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/ SortEditForm.php, line 24
Class
- SortEditForm
- Class SortEditForm.
Namespace
Drupal\entity_share_server\FormCode
public function form(array $form, FormStateInterface $form_state) {
// Check if the sort exists.
if (!$this
->sortIdExists()) {
drupal_set_message($this
->t('There is no sort with the ID @id in this channel', [
'@id' => $this
->getsortId(),
]), 'error');
return [];
}
$form = parent::form($form, $form_state);
/** @var \Drupal\entity_share_server\Entity\ChannelInterface $channel */
$channel = $this->entity;
$channel_sorts = $channel
->get('channel_sorts');
$sort_id = $this
->getsortId();
$form['path'] = [
'#type' => 'textfield',
'#title' => $this
->t('Path'),
'#description' => $this
->t('Enter the machine name of the field / property you want to sort on. You can reference field / property of a referenced entity. Example: uid.name for the name of the author.'),
'#required' => TRUE,
'#default_value' => $channel_sorts[$sort_id]['path'],
];
$form['sort_id'] = [
'#type' => 'machine_name',
'#title' => $this
->t('ID'),
'#default_value' => $sort_id,
'#machine_name' => [
'source' => [
'path',
],
'exists' => [
$this,
'sortExists',
],
],
'#disabled' => TRUE,
];
$form['direction'] = [
'#type' => 'select',
'#title' => $this
->t('Direction'),
'#options' => $this
->getDirectionOptions(),
'#default_value' => $channel_sorts[$sort_id]['direction'],
'#required' => TRUE,
];
$form['weight'] = [
'#type' => 'number',
'#title' => $this
->t('Weight'),
'#default_value' => $channel_sorts[$sort_id]['weight'],
'#required' => TRUE,
];
return $form;
}