Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alloy Magnetic
Compose
Commits
a2172f20
Commit
a2172f20
authored
5 years ago
by
Jordan White
Browse files
Options
Download
Email Patches
Plain Diff
Add submission handler
parent
2781412b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compose.module
+2
-1
compose.module
src/Plugin/Field/FieldWidget/ComposeWidget.php
+43
-11
src/Plugin/Field/FieldWidget/ComposeWidget.php
with
45 additions
and
12 deletions
+45
-12
compose.module
View file @
a2172f20
...
...
@@ -266,6 +266,7 @@ function compose_inline_entity_form_reference_form_alter(&$reference_form, &$for
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Select'
),
'#name'
=>
'ief-reference-add-existing-'
.
$entity_id
,
'#ief_row_delta'
=>
$i
,
'#limit_validation_errors'
=>
[
$reference_form
[
'#parents'
]],
'#id'
=>
'entity-id-'
.
$entity_id
,
'#attributes'
=>
[
...
...
@@ -282,8 +283,8 @@ function compose_inline_entity_form_reference_form_alter(&$reference_form, &$for
],
],
];
$reference_form
[
'entity_table'
][
$i
][
'button'
][
'#submit'
][]
=
'Drupal\compose\Plugin\Field\FieldWidget\ComposeWidget::addExistingSubmit'
;
$reference_form
[
'entity_table'
][
$i
][
'button'
][
'#submit'
][]
=
'Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex::submitCloseRow'
;
InlineEntityFormComplex
::
addSubmitCallbacks
(
$reference_form
[
'entity_table'
][
$i
][
'button'
]);
$i
++
;
}
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/Field/FieldWidget/ComposeWidget.php
View file @
a2172f20
...
...
@@ -86,20 +86,13 @@ class ComposeWidget extends InlineEntityFormComplex implements ContainerFactoryP
if
(
$entity_id
!==
NULL
&&
$entity_type
!==
NULL
)
{
$storage
=
\
Drupal
::
entityTypeManager
()
->
getStorage
(
$entity_type
);
$entity
=
$storage
->
load
(
$entity_id
);
$entities
=
&
$form_state
->
get
([
'inline_entity_form'
,
$ief_id
,
'entities'
]);
$entities
=
$form_state
->
get
([
'inline_entity_form'
,
$ief_id
,
'entities'
]);
// Determine the correct weight of the new element.
$weight
=
0
;
if
(
$entities
)
{
$weight
=
max
(
array_keys
(
$entities
))
+
1
;
}
$entities
[]
=
[
'entity'
=>
$entity
,
'weight'
=>
$weight
,
'form'
=>
NULL
,
'needs_save'
=>
FALSE
,
];
$element
[
'entities'
][]
=
[
'#entity'
=>
$entity
,
'#label'
=>
$entity
->
label
(),
...
...
@@ -113,9 +106,6 @@ class ComposeWidget extends InlineEntityFormComplex implements ContainerFactoryP
// Pass along the IEF form id, field name and entity type.
$element
[
'entities'
][
'#form_id'
]
=
$ief_id
;
$form_state
->
set
([
'inline_entity_form'
,
$ief_id
,
'entities'
],
$entities
);
$form_state
->
setCached
(
TRUE
);
}
return
$element
;
...
...
@@ -165,4 +155,46 @@ class ComposeWidget extends InlineEntityFormComplex implements ContainerFactoryP
}
}
}
/**
* Button #submit callback: Add existing Compose buttons.
*
* @param $form
* The complete parent form.
* @param $form_state
* The form state of the parent form.
*/
public
static
function
addExistingSubmit
(
$form
,
FormStateInterface
$form_state
)
{
$element
=
inline_entity_form_get_element
(
$form
,
$form_state
);
$ief_id
=
$element
[
'#ief_id'
];
$triggering_element
=
$form_state
->
getTriggeringElement
();
$button_name
=
$triggering_element
[
'#name'
];
$instance
=
$form_state
->
get
([
'inline_entity_form'
,
$ief_id
,
'instance'
]);
$entity_type
=
$instance
->
getSetting
(
'target_type'
);
if
(
strpos
(
$button_name
,
'ief-reference-add-existing-'
)
!==
FALSE
)
{
$entity_id
=
str_replace
(
'ief-reference-add-existing-'
,
''
,
$button_name
);
}
if
(
$entity_id
!==
NULL
&&
$entity_type
!==
NULL
)
{
$storage
=
\
Drupal
::
entityTypeManager
()
->
getStorage
(
$entity_type
);
$entity
=
$storage
->
load
(
$entity_id
);
$entities
=
&
$form_state
->
get
([
'inline_entity_form'
,
$ief_id
,
'entities'
]);
// Determine the correct weight of the new element.
$weight
=
0
;
if
(
$entities
)
{
$weight
=
max
(
array_keys
(
$entities
))
+
1
;
}
$entities
[]
=
[
'entity'
=>
$entity
,
'weight'
=>
$weight
,
'form'
=>
NULL
,
'needs_save'
=>
FALSE
,
];
$form_state
->
set
([
'inline_entity_form'
,
$ief_id
,
'entities'
],
$entities
);
$form_state
->
setRebuild
();
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help