public function PriceModifierForm::form in Price 8
Same name and namespace in other branches
- 3.x src/Form/PriceModifierForm.php \Drupal\price\Form\PriceModifierForm::form()
- 3.0.x src/Form/PriceModifierForm.php \Drupal\price\Form\PriceModifierForm::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/ PriceModifierForm.php, line 34
Class
Namespace
Drupal\price\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$entity = $this->entity;
$entity_type = $entity
->getEntityType();
$entity_label = $entity_type
->getLabel();
if ($this->operation == 'add') {
$form['#title'] = $this
->t('Add ' . $entity_label);
}
else {
$form['#title'] = $this
->t('Edit %label ' . $entity_label, [
'%label' => $entity
->label(),
]);
}
$form['label'] = [
'#title' => t('Label'),
'#type' => 'textfield',
'#default_value' => $entity
->label(),
'#description' => $this
->t('The human-readable name of this entity.'),
'#required' => TRUE,
'#size' => 30,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $entity
->id(),
'#maxlength' => EntityTypeInterface::ID_MAX_LENGTH,
'#disabled' => !$entity
->isNew(),
'#machine_name' => [
'exists' => [
$this,
'exists',
],
],
'#description' => $this
->t('A unique machine-readable name for this entity. It must only contain lowercase letters, numbers, and underscores.'),
];
return $form;
}