Commit fd938414 authored by Pawel G's avatar Pawel G

Slightly simplify commerce form submit workaround

parent 1a75d1bc
...@@ -42,7 +42,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) { ...@@ -42,7 +42,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
else { else {
return; return;
} }
$form['#simple_sitemap'] = $f; $form['simple_sitemap']['#simple_sitemap'] = $f;
// Add submission handler. // Add submission handler.
if (isset($form['actions']['submit']['#submit'])) { if (isset($form['actions']['submit']['#submit'])) {
...@@ -62,16 +62,15 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) { ...@@ -62,16 +62,15 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
*/ */
function simple_sitemap_entity_form_submit($form, &$form_state) { function simple_sitemap_entity_form_submit($form, &$form_state) {
// Only make changes in DB if sitemap settings actually changed. $values = $form_state->getValues();
if (Form::valuesChanged($form, $form_state)) {
// 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'); $sitemap = \Drupal::service('simple_sitemap.generator');
$f = $form['#simple_sitemap']; $f = $form['simple_sitemap']['#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'];
}
// Get current entity type sitemap settings. // Get current entity type sitemap settings.
$entity_types = $sitemap->getConfig('entity_types'); $entity_types = $sitemap->getConfig('entity_types');
......
...@@ -232,11 +232,9 @@ class Form { ...@@ -232,11 +232,9 @@ class Form {
* @return bool * @return bool
* TRUE if simple_sitemap form values have been altered by the user. * TRUE if simple_sitemap form values have been altered by the user.
*/ */
public static function valuesChanged($form, $form_state) { public static function valuesChanged($form, $values) {
$values = $form_state->getValues();
foreach (array('simple_sitemap_index_content', 'simple_sitemap_priority', 'simple_sitemap_regenerate_now') as $field_name) { 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'] if (isset($values[$field_name]) && $values[$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.
return TRUE; return TRUE;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment