Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
layout_paragraphs
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
layout_paragraphs
Commits
5dbfa34e
Commit
5dbfa34e
authored
1 year ago
by
Justin Toupin
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3438379
: Set _referringItem in LayoutParagraphsLayout
parent
6c589733
No related branches found
No related tags found
1 merge request
!158
Resolve #3438379 "Set referringitem in"
Pipeline
#138960
passed with warnings
1 year ago
Stage: build
Stage: validate
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Contracts/ComponentFormInterface.php
+13
-0
13 additions, 0 deletions
src/Contracts/ComponentFormInterface.php
src/Form/ComponentFormBase.php
+22
-1
22 additions, 1 deletion
src/Form/ComponentFormBase.php
src/LayoutParagraphsLayout.php
+13
-4
13 additions, 4 deletions
src/LayoutParagraphsLayout.php
with
48 additions
and
5 deletions
src/Contracts/ComponentFormInterface.php
+
13
−
0
View file @
5dbfa34e
...
@@ -97,4 +97,17 @@ interface ComponentFormInterface extends FormInterface {
...
@@ -97,4 +97,17 @@ interface ComponentFormInterface extends FormInterface {
*/
*/
public
function
successfulAjaxSubmit
(
array
$form
,
FormStateInterface
$form_state
);
public
function
successfulAjaxSubmit
(
array
$form
,
FormStateInterface
$form_state
);
/**
* Get the form mode.
*/
public
function
getFormMode
();
/**
* Set the form view mode.
*
* @param string $view_mode
* The view mode.
*/
public
function
setFormMode
(
$view_mode
);
}
}
This diff is collapsed.
Click to expand it.
src/Form/ComponentFormBase.php
+
22
−
1
View file @
5dbfa34e
...
@@ -83,6 +83,13 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf
...
@@ -83,6 +83,13 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf
*/
*/
protected
$entityRepository
;
protected
$entityRepository
;
/**
* The form mode to use for rendering the form.
*
* @var string
*/
protected
$formMode
=
'default'
;
/**
/**
* {@inheritDoc}
* {@inheritDoc}
*/
*/
...
@@ -157,7 +164,7 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf
...
@@ -157,7 +164,7 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf
FormStateInterface
$form_state
)
{
FormStateInterface
$form_state
)
{
$this
->
initFormLangcodes
(
$form_state
);
$this
->
initFormLangcodes
(
$form_state
);
$display
=
EntityFormDisplay
::
collectRenderDisplay
(
$this
->
paragraph
,
'default'
);
$display
=
EntityFormDisplay
::
collectRenderDisplay
(
$this
->
paragraph
,
$this
->
getFormMode
()
);
$display
->
buildForm
(
$this
->
paragraph
,
$form
,
$form_state
);
$display
->
buildForm
(
$this
->
paragraph
,
$form
,
$form_state
);
$this
->
paragraphType
=
$this
->
paragraph
->
getParagraphType
();
$this
->
paragraphType
=
$this
->
paragraph
->
getParagraphType
();
$lp_config
=
$this
->
config
(
'layout_paragraphs.settings'
);
$lp_config
=
$this
->
config
(
'layout_paragraphs.settings'
);
...
@@ -607,4 +614,18 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf
...
@@ -607,4 +614,18 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf
return
[];
return
[];
}
}
/**
* {@inheritDoc}
*/
public
function
getFormMode
()
{
return
$this
->
formMode
;
}
/**
* {@inheritDoc}
*/
public
function
setFormMode
(
$view_mode
)
{
$this
->
formMode
=
$view_mode
;
}
}
}
This diff is collapsed.
Click to expand it.
src/LayoutParagraphsLayout.php
+
13
−
4
View file @
5dbfa34e
...
@@ -164,6 +164,11 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
...
@@ -164,6 +164,11 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
* @return $this
* @return $this
*/
*/
public
function
setParagraphsReferenceField
(
EntityReferenceFieldItemListInterface
$paragraphs_reference_field
)
{
public
function
setParagraphsReferenceField
(
EntityReferenceFieldItemListInterface
$paragraphs_reference_field
)
{
foreach
(
$paragraphs_reference_field
as
$key
=>
$field_item
)
{
if
(
$field_item
->
entity
)
{
$paragraphs_reference_field
[
$key
]
->
entity
->
_referringItem
=
$field_item
;
}
}
$this
->
paragraphsReferenceField
=
$paragraphs_reference_field
;
$this
->
paragraphsReferenceField
=
$paragraphs_reference_field
;
return
$this
;
return
$this
;
}
}
...
@@ -399,9 +404,11 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
...
@@ -399,9 +404,11 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
$new_paragraph
=
$component
->
getEntity
();
$new_paragraph
=
$component
->
getEntity
();
$new_paragraph
->
setParentEntity
(
$this
->
getEntity
(),
$this
->
getFieldName
());
$new_paragraph
->
setParentEntity
(
$this
->
getEntity
(),
$this
->
getFieldName
());
// Splice the new paragraph into the field item list.
// Splice the new paragraph into the field item list.
$list
=
$this
->
paragraphsReferenceField
->
getValue
();
$item_list
=
$this
->
getParagraphsReferenceField
();
$list
=
$item_list
->
getValue
();
$list
[]
=
[
'entity'
=>
$new_paragraph
];
$list
[]
=
[
'entity'
=>
$new_paragraph
];
$this
->
paragraphsReferenceField
->
setValue
(
$list
);
$item_list
->
setValue
(
$list
);
$this
->
setParagraphsReferenceField
(
$item_list
);
}
}
else
{
else
{
// @todo Throw exception.
// @todo Throw exception.
...
@@ -470,11 +477,13 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
...
@@ -470,11 +477,13 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface {
$new_paragraph
=
$new_component
->
getEntity
();
$new_paragraph
=
$new_component
->
getEntity
();
$new_paragraph
->
setParentEntity
(
$this
->
getEntity
(),
$this
->
getFieldName
());
$new_paragraph
->
setParentEntity
(
$this
->
getEntity
(),
$this
->
getFieldName
());
// Splice the new paragraph into the field item list.
// Splice the new paragraph into the field item list.
$list
=
$this
->
paragraphsReferenceField
->
getValue
();
$item_list
=
$this
->
getParagraphsReferenceField
();
$list
=
$item_list
->
getValue
();
$delta
=
$this
->
getComponentDeltaByUuid
(
$sibling_uuid
);
$delta
=
$this
->
getComponentDeltaByUuid
(
$sibling_uuid
);
$delta
+=
$delta_offset
;
$delta
+=
$delta_offset
;
array_splice
(
$list
,
$delta
,
0
,
[
'entity'
=>
$new_paragraph
]);
array_splice
(
$list
,
$delta
,
0
,
[
'entity'
=>
$new_paragraph
]);
$this
->
paragraphsReferenceField
->
setValue
(
$list
);
$item_list
->
setValue
(
$list
);
$this
->
setParagraphsReferenceField
(
$item_list
);
}
}
else
{
else
{
// @todo Throw exception.
// @todo Throw exception.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment