Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve normalizing of UI Patterns submitted configuration #320

Open
nedjo opened this issue Dec 17, 2020 · 0 comments
Open

Improve normalizing of UI Patterns submitted configuration #320

nedjo opened this issue Dec 17, 2020 · 0 comments

Comments

@nedjo
Copy link

nedjo commented Dec 17, 2020

In PatternDisplayFormTrait:processFormStateValues() the submitted values from a UI Patterns configuration form are normalized before being saved.

There are a couple of places where edge cases lead to cruft being saved.

First, the $settings['variants'] key is unset only conditionally, that is, in the case that there's a selected variant:

    if (isset($settings['variants']) && isset($settings['variants'][$settings['pattern']])) {
      $settings['pattern_variant'] = $settings['variants'][$settings['pattern']];
      unset($settings['variants']);
    }

The result is that, when the current pattern doesn't have a selected variant (possibly because it doesn't support variants), the (always superfluous) 'variants' data are saved for all available patterns.

Proposed fix:

    if (isset($settings['variants'])) {
      if (isset($settings['variants'][$settings['pattern']]) {
        $settings['pattern_variant'] = $settings['variants'][$settings['pattern']];
      }
      unset($settings['variants']);
    }

Second, there are edge cases where the code normalizing the $settings['pattern_mapping'] can also leave cruft.

The current code is:

    // Normalize only when necessary.
    if (isset($settings['pattern_mapping'][$settings['pattern']]['settings'])) {
      ...
    }

If there is no selected pattern - for example, in a context where the pattern is not required - the non-normalized data for all patterns are saved.

Proposed fix:

    // Normalize only when necessary.
    if (isset($settings['pattern_mapping'][$settings['pattern']]['settings'])) {
      ...
    }
    else {
      unset($settings['pattern_mapping']);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant