I have the following EntityForm and I want to add a entity_reference_revisions field for the paragraph entity with the allowed bundle type orga_structure.
I searched the web but haven’t found a hint to resolve this.
$form(‘target’) is the element I tried, but it isn’t rendered.
class AbsenceConfigForm extends EntityForm {
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$absence_config = $this->entity;
$form('label') = (
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $absence_config->label(),
'#description' => $this->t("Label for the Absence config."),
'#required' => TRUE,
);
$form('id') = (
'#type' => 'machine_name',
'#default_value' => $absence_config->id(),
'#machine_name' => (
'exists' => 'Drupalks_absenceEntityAbsenceConfig::load',
),
'#disabled' => !$absence_config->isNew(),
);
/* You will need additional form elements for your custom properties. */
$form('target') = (
'#type' => 'entity_reference_revisions',
'#handler' => 'default:paragraph',
'#handler_settings' => (
'target_type' => (
'orga_structure',
),
),
);
// $form('target') = BaseFieldDefinition::create('entity_reference_revisions')
// ->setLabel(t('Skill'))
// ->setDescription(t('The ID of the skill'))
// ->setRevisionable(TRUE)
// ->setSetting('handler', 'default:paragraph')
// ->setSetting('handler_settings', ('target_bundles' => ('orga_structure' => 'orga_structure')))
// ->setSetting('handler_settings', ('negate' => 0))
// ->setTranslatable(TRUE)
// ->setDisplayOptions('form', (
// 'type' => 'entity_reference_autocomplete',
// 'weight' => 5,
// 'settings' => (
// 'match_operator' => 'CONTAINS',
// 'size' => '60',
// 'autocomplete_type' => 'tags',
// 'placeholder' => '',
// ),
// ))
// ->setDisplayConfigurable('form', TRUE);
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
$absence_config = $this->entity;
$status = $absence_config->save();
switch ($status) {
case SAVED_NEW:
$this->messenger()->addMessage($this->t('Created the %label Absence config.', (
'%label' => $absence_config->label(),
)));
break;
default:
$this->messenger()->addMessage($this->t('Saved the %label Absence config.', (
'%label' => $absence_config->label(),
)));
}
$form_state->setRedirectUrl($absence_config->toUrl('collection'));
}
}
Update:
I would like to achieve that the fields specified in the paragraph are rendered in this form.