Skip to content
Snippets Groups Projects

Add paragraphDefaults value and means to pass values in form builder.

1 file
+ 15
2
Compare changes
  • Side-by-side
  • Inline
@@ -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;
}
}
Loading