public function CorrespondingReferenceForm::form in Corresponding Entity References 8.4
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/ CorrespondingReferenceForm.php, line 56
Class
- CorrespondingReferenceForm
- Form handler for corresponding reference add and edit forms.
Namespace
Drupal\cer\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/** @var CorrespondingReferenceInterface $correspondingReference */
$correspondingReference = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $correspondingReference
->label(),
'#description' => $this
->t("Label for the corresponding reference."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $correspondingReference
->id(),
'#machine_name' => [
'exists' => [
$this,
'exists',
],
],
'#disabled' => !$correspondingReference
->isNew(),
];
$form['first_field'] = [
'#type' => 'select',
'#title' => $this
->t('First field'),
'#description' => $this
->t('Select the first field.'),
'#options' => $this
->getFieldOptions(),
'#default_value' => $correspondingReference
->getFirstField(),
'#required' => TRUE,
];
$form['second_field'] = [
'#type' => 'select',
'#title' => $this
->t('Second field'),
'#description' => $this
->t('Select the corresponding field. It may be the same field.'),
'#options' => $this
->getFieldOptions(),
'#default_value' => $correspondingReference
->getSecondField(),
'#required' => TRUE,
];
$form['bundles'] = [
'#type' => 'select',
'#title' => $this
->t('Bundles'),
'#description' => $this
->t('Select the bundles which should correspond to one another when they have one of the corresponding fields.'),
'#options' => $this
->getBundleOptions(),
'#multiple' => TRUE,
'#default_value' => $this
->getBundleValuesForForm($correspondingReference
->getBundles()),
];
$form['enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enabled'),
'#description' => $this
->t('When enabled, corresponding references will be automatically created upon saving an entity.'),
'#default_value' => $correspondingReference
->isEnabled(),
];
return $form;
}