Overrides ParagraphsBehaviorBase::buildConfigurationForm
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$paragraphs_type = $form_state
->getFormObject()
->getEntity();
if ($paragraphs_type
->isNew()) {
return [];
}
$field_definitions = $this->entityFieldManager
->getFieldDefinitions('paragraph', $paragraphs_type
->id());
$fields = array_filter($field_definitions, function ($definition) {
return $definition instanceof FieldConfigInterface && $definition
->getFieldStorageDefinition()
->getCardinality() !== 1;
});
$options = array_map(function ($definition) {
return $definition
->getLabel();
}, $fields);
if (!empty($options)) {
$form['paragraph_accordion_field'] = [
'#type' => 'select',
'#title' => $this
->t('Accordion field'),
'#description' => $this
->t('Choose a field to be used as the accordion container.'),
'#options' => $options,
'#default_value' => $this->configuration['paragraph_accordion_field'],
];
}
else {
$form['message'] = [
'#type' => 'container',
'#markup' => $this
->t('There are no fields available with the cardinality greater than one. Please add at least one in the <a href=":link">Manage fields</a> page.', [
':link' => Url::fromRoute("entity.{$paragraphs_type->getEntityType()->getBundleOf()}.field_ui_fields", [
$paragraphs_type
->getEntityTypeId() => $paragraphs_type
->id(),
])
->toString(),
]),
'#attributes' => [
'class' => [
'messages messages--error',
],
],
];
}
return $form;
}