public function FlagForListForm::form in Flag Lists 8
Same name and namespace in other branches
- 4.0.x src/Form/FlagForListForm.php \Drupal\flag_lists\Form\FlagForListForm::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
- src/
Form/ FlagForListForm.php, line 17
Class
- FlagForListForm
- Class FlagForListForm.
Namespace
Drupal\flag_lists\FormCode
public function form(array $form, FormStateInterface $form_state) {
/* You will need additional form elements for your custom properties. */
$form = parent::form($form, $form_state);
$flagService = \Drupal::service('flaglists');
$account = \Drupal::currentUser();
$entity = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Template name'),
'#maxlength' => 255,
'#default_value' => $entity
->label(),
'#description' => $this
->t("Template name for the Flag for list."),
'#required' => TRUE,
'#weight' => -3,
];
$existing_flags = $flagService
->getAllFlagForList(NULL, NULL);
$options = [];
foreach ($existing_flags as $flag) {
if ($flag
->hasBaseFlag()) {
$options[$flag
->get('id')] = $flag
->label();
}
}
$form['base_flag'] = [
'#type' => 'select',
'#title' => $this
->t('Template flag'),
'#required' => TRUE,
'#default_value' => $entity
->getBaseFlag(),
'#options' => $options,
];
return $form;
}