Problem/Motivation

Content editors may find it confusing to see the "Save and Clear Cloudflare Cache" button, if they are not aware of "Cloudflare" or "caching". Maybe this could be addressed by documentation and training, but I wonder if the maintainers are interested having a config option "Replace default save button with Clear Cloudflare Cache button", which, if enabled, will replace the save button and style the cloudflare_node_cc button as primary with the default text, Save.

I think this feature can reduce stress of content editors without altering the interface or slowing down the site.

This feature should be off by default so site builders will not be surprised about the missing button.

Steps to reproduce

  1. Edit a node.
  2. Locate the Save button.
  3. See a primary Save, and a secondary "Save and clear cloudflare cache".

Proposed resolution

  1. Add a config item "Replace default save button with cloudflare node cache clear button"
  2. If this config item exists and set to true, then Remove the default submit button, change the style to primary, and change the text to translated "Save".
  3. Else, output the cloudflare node cache clear button alongside the save button (no change).

Remaining tasks

  • Implement the change.
  • Collect feedback on feature
  • Collect feedback on implementation

User interface changes

Disappearance of the cloudflare node cache clear button if the feature is turned on by the admin.

API changes

None.

Data model changes

None.

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

hktang created an issue. See original summary.

hktang’s picture

I added pull request and would appreciate your review. Thank you!

hktang’s picture

Issue summary: View changes
hktang’s picture

Status: Active » Needs review

hktang changed the visibility of the branch 3494694-option-to-replace to hidden.

hktang changed the visibility of the branch 3494694-option-to-replace to active.

luukyb’s picture

Status: Needs review » Needs work
Issue tags: +Nara2025

Hi @hktang,
Great meeting you at DrupalCon Nara!
This is great, I think best would be to have the checkbox to activate/deactivate this functionnality and when checked:

  • "Save" button is renamed "Save without purging cloudflare cache", and becomes a secondary button
  • "Save and purge cloudflare cache" is renamed "Save" and becomes the primary button

So the two options are offered to the user, but the default becomes the renamed purge button. This avoid confusion to most users and enable the new feature by default. This would be my suggestion.

Thanks!

damienmckenna’s picture

I think this could work really well alongside #3479228: Add disable option and confirm option as safeguards, so that you could use Config Split or settings.php hardcoding to control which environments have Cloudflare enabled using #3479228, then use this change to make the "save" button always clear the caches on environments where CF is enabled.

damienmckenna’s picture

Contrary to #8, could this actually go a step further and just add an extra submit handler on $form['actions']['submit'], rather than as part of $form['actions']['cf_purge'], if the option is enabled? That way it would end up something like this:

      if ($user && $user->hasPermission('cloudflare_node_cc purge cache per node')) {
        $config = \Drupal::config('cloudflare_node_cc.settings');

        // Just add the Cloudflare purge operation to the normal save operation.
        if ($config->get('replace_default_save_button')) {
          $form['actions']['submit']['#submit'][] = '_cloudflare_node_cc_purge_node';
        }

        // Add a new button to purge CF.
        else {
          $cf_purge_button = !empty($form['actions']['submit']) ? $form['actions']['submit'] : [];
          $cf_purge_button['#value'] = $t('Save & Purge Cloudflare Cache');
          $cf_purge_button['#button_type'] = 'secondary';
          $cf_purge_button['#submit'][] = '_cloudflare_node_cc_purge_node';
          $cf_purge_button['#weight']++;
          $form['actions']['cf_purge'] = $cf_purge_button;
        }
      }
damienmckenna’s picture

Status: Needs work » Needs review
Related issues: +#3507723: Use configuration for storing configuration

damienmckenna’s picture

StatusFileSize
new4.04 KB

A version of MR 10 that works on top of #3507723: Use configuration for storing configuration.

damienmckenna’s picture

damienmckenna’s picture

  • damienmckenna committed 692e3008 on 1.x
    Issue #3494694 by hktang, luukyb, DamienMcKenna: Optionally purge cache...
damienmckenna’s picture

Status: Needs review » Fixed

Committed. Thank you.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.