Commit fd938414 authored by gbyte.co's avatar gbyte.co

Slightly simplify commerce form submit workaround

parent 1a75d1bc
......@@ -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');
......
......@@ -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;
}
}
......
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