Problem/Motivation

My team lead that knows a lot more about CSP than I do raised this in a work chat channel and it sounded like a legit quality of life fix that could be a quick win.

Steps to reproduce

Use the CSP settings form at any time.

Proposed resolution

Swap the default tab that is selected.

User interface changes

Default selected tab when you first hit the form.

API changes

None

Data model changes

None

CommentFileSizeAuthor
Screenshot from 2024-02-02 09-10-44.png31.06 KBgold

Issue fork csp-3418744

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Gold created an issue. See original summary.

gapple’s picture

I think I agree with that change - IIRC, my thought was that viewing that there is an enforced policy and its values would be important.
But if editing is the priority then having the report-only policy default makes sense. There's also the tab summary which indicates that a policy is enabled (and how many directives), and #2987910: Copy configuration between report-only and enforced would help with suggested workflow of tweaking the report-only policy, then copying it to enforced after testing.

I would not switch the order of the form tabs though. There is a following line that causes the switch to have the enforced policy tab as default if it is enabled:

      if ($config->get($policyTypeKey . '.enable')) {
        $form['policies']['#default_tab'] = 'edit-' . $policyTypeKey;
      }
gold’s picture

@grapple, I did look at that snippet and tracked back to where the config for that value was being set. It started getting a bit convoluted though and I had a bit of time pressure.

This value seems to be being set in 1 place when the form is first submitted in CspSettingsForm.php:631.

I tried flipping the order that $policyTypeKey was processing at L626 but that didn't make any difference either.

I think the issue is tying the $form['policies']['#default_tab'] to the value in that config var.

An alternative could be to add #weight to the $form[$policyTypeKey] array.

I'll push an update for that in a moment. Let me know what you think.

  • gapple committed b34ab2fd on 2.x
    Issue #3418744: Always set report-only options as default active tab
    

  • gapple committed b9cffa1e on 8.x-1.x
    Issue #3418744: Always set report-only options as default active tab
    
gapple’s picture

Title: Swap default active tab when you first hit the CSP settings form » Consistent default active tab on the CSP settings form
Status: Active » Fixed

I've just set the report-only options to always be default - I don't think having it switch to enforced if that's the only enabled policy provides much benefit, and having it always show the first possible tab is clear and consistent behaviour (that also reduces the likelyhood of making inadvertent changes to the enforced policy).

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.