Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
simple_sitemap
Commits
fd938414
Commit
fd938414
authored
Jun 09, 2016
by
Pawel G
Browse files
Slightly simplify commerce form submit workaround
parent
1a75d1bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
simple_sitemap.module
View file @
fd938414
...
...
@@ -42,7 +42,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
else
{
return
;
}
$form
[
'#simple_sitemap'
]
=
$f
;
$form
[
'
simple_sitemap'
][
'
#simple_sitemap'
]
=
$f
;
// Add submission handler.
if
(
isset
(
$form
[
'actions'
][
'submit'
][
'#submit'
]))
{
...
...
@@ -62,16 +62,15 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
*/
function
simple_sitemap_entity_form_submit
(
$form
,
&
$form_state
)
{
// Only make changes in DB if sitemap settings actually changed.
if
(
Form
::
valuesChanged
(
$form
,
$form_state
))
{
$values
=
$form_state
->
getValues
();
// Fix for values appearing in a sub array on a commerce product entity.
$values
=
isset
(
$values
[
'simple_sitemap'
])
?
$values
[
'simple_sitemap'
]
:
$values
;
// Only make changes in DB if sitemap settings actually changed.
if
(
Form
::
valuesChanged
(
$form
,
$values
))
{
$sitemap
=
\
Drupal
::
service
(
'simple_sitemap.generator'
);
$f
=
$form
[
'#simple_sitemap'
];
$values
=
$form_state
->
getValues
();
// Fix for values appearing in a sub array on a commerce product entity.
if
(
isset
(
$values
[
'simple_sitemap'
]))
{
$values
=
$values
[
'simple_sitemap'
];
}
$f
=
$form
[
'simple_sitemap'
][
'#simple_sitemap'
];
// Get current entity type sitemap settings.
$entity_types
=
$sitemap
->
getConfig
(
'entity_types'
);
...
...
src/Form.php
View file @
fd938414
...
...
@@ -232,11 +232,9 @@ class Form {
* @return bool
* TRUE if simple_sitemap form values have been altered by the user.
*/
public
static
function
valuesChanged
(
$form
,
$form_state
)
{
$values
=
$form_state
->
getValues
();
public
static
function
valuesChanged
(
$form
,
$values
)
{
foreach
(
array
(
'simple_sitemap_index_content'
,
'simple_sitemap_priority'
,
'simple_sitemap_regenerate_now'
)
as
$field_name
)
{
if
(
isset
(
$values
[
'simple_sitemap'
][
$field_name
])
&&
$values
[
'simple_sitemap'
][
$field_name
]
!=
$form
[
'simple_sitemap'
][
$field_name
][
'#default_value'
]
||
isset
(
$values
[
$field_name
])
&&
$values
[
$field_name
]
!=
$form
[
'simple_sitemap'
][
$field_name
][
'#default_value'
])
{
// Fix for values appearing in a sub array on a commerce product entity.
if
(
isset
(
$values
[
$field_name
])
&&
$values
[
$field_name
]
!=
$form
[
'simple_sitemap'
][
$field_name
][
'#default_value'
])
{
return
TRUE
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment