Skip to content
Snippets Groups Projects
Commit ad117e41 authored by Justin Toupin's avatar Justin Toupin
Browse files

Issue #3468162: Allow default values for paragraphs to be passed to InsertComponentForm

parent 3d47998f
No related branches found
No related tags found
1 merge request!177Add paragraphDefaults value and means to pass values in form builder.
Pipeline #254165 passed with warnings
...@@ -26,6 +26,13 @@ class InsertComponentForm extends ComponentFormBase { ...@@ -26,6 +26,13 @@ class InsertComponentForm extends ComponentFormBase {
*/ */
protected $domSelector; protected $domSelector;
/**
* Default values for new paragraph.
*
* @var array
*/
protected $paragraphDefaults = [];
/** /**
* The jQuery insertion method to use for adding the new component. * The jQuery insertion method to use for adding the new component.
* *
...@@ -84,6 +91,8 @@ class InsertComponentForm extends ComponentFormBase { ...@@ -84,6 +91,8 @@ class InsertComponentForm extends ComponentFormBase {
* The uuid of the sibling component. * The uuid of the sibling component.
* @param string $placement * @param string $placement
* Where to place the new component - either "before" or "after". * Where to place the new component - either "before" or "after".
* @param array $paragraph_defaults
* Default values for the new paragraph.
*/ */
public function buildForm( public function buildForm(
array $form, array $form,
...@@ -93,9 +102,13 @@ class InsertComponentForm extends ComponentFormBase { ...@@ -93,9 +102,13 @@ class InsertComponentForm extends ComponentFormBase {
string $parent_uuid = NULL, string $parent_uuid = NULL,
string $region = NULL, string $region = NULL,
string $sibling_uuid = NULL, string $sibling_uuid = NULL,
string $placement = NULL string $placement = NULL,
array $paragraph_defaults = []
) { ) {
if (!empty($paragraph_defaults)) {
$this->paragraphDefaults = $paragraph_defaults;
}
$this->setLayoutParagraphsLayout($layout_paragraphs_layout); $this->setLayoutParagraphsLayout($layout_paragraphs_layout);
$langcode = $this->layoutParagraphsLayout->getEntity()->language()->getId(); $langcode = $this->layoutParagraphsLayout->getEntity()->language()->getId();
$this->paragraph = $this->newParagraph($paragraph_type, $langcode); $this->paragraph = $this->newParagraph($paragraph_type, $langcode);
...@@ -231,7 +244,7 @@ class InsertComponentForm extends ComponentFormBase { ...@@ -231,7 +244,7 @@ class InsertComponentForm extends ComponentFormBase {
$bundle_key => $paragraph_type->id(), $bundle_key => $paragraph_type->id(),
$langcode_key => $langcode, $langcode_key => $langcode,
'_layoutParagraphsLayout' => $this->getLayoutParagraphsLayout(), '_layoutParagraphsLayout' => $this->getLayoutParagraphsLayout(),
]); ] + $this->paragraphDefaults);
return $paragraph; return $paragraph;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment