protected function InlineParagraphsWidget::buildSelectAddMode in Paragraphs 8
Builds list of actions based on paragraphs type.
Return value
array The form element array.
1 call to InlineParagraphsWidget::buildSelectAddMode()
- InlineParagraphsWidget::buildAddActions in src/
Plugin/ Field/ FieldWidget/ InlineParagraphsWidget.php - Add 'add more' button, if not working with a programmed form.
File
- src/
Plugin/ Field/ FieldWidget/ InlineParagraphsWidget.php, line 1088
Class
- InlineParagraphsWidget
- Plugin implementation of the 'entity_reference paragraphs' widget.
Namespace
Drupal\paragraphs\Plugin\Field\FieldWidgetCode
protected function buildSelectAddMode() {
$field_name = $this->fieldDefinition
->getName();
$title = $this->fieldDefinition
->getLabel();
$add_more_elements['add_more_select'] = [
'#type' => 'select',
'#options' => $this
->getAccessibleOptions(),
'#title' => $this
->t('@title type', [
'@title' => $this
->getSetting('title'),
]),
'#label_display' => 'hidden',
];
$text = $this
->t('Add @title', [
'@title' => $this
->getSetting('title'),
]);
if ($this->realItemCount > 0) {
$text = $this
->t('Add another @title', [
'@title' => $this
->getSetting('title'),
]);
}
$add_more_elements['add_more_button'] = [
'#type' => 'submit',
'#name' => strtr($this->fieldIdPrefix, '-', '_') . '_add_more',
'#value' => $text,
'#attributes' => [
'class' => [
'field-add-more-submit',
],
],
'#limit_validation_errors' => [
array_merge($this->fieldParents, [
$field_name,
'add_more',
]),
],
'#submit' => [
[
get_class($this),
'addMoreSubmit',
],
],
'#ajax' => [
'callback' => [
get_class($this),
'addMoreAjax',
],
'wrapper' => $this->fieldWrapperId,
'effect' => 'fade',
],
];
$add_more_elements['add_more_button']['#suffix'] = $this
->t(' to %type', [
'%type' => $title,
]);
return $add_more_elements;
}