From https://www.drupal.org/project/tr_rulez/issues/3053884

Reaction Rules and Rules Components are Drupal configurations, so Drupal core provides all sorts of tools that can be used for Rules and Components. Some of these tools perform the same function as purpose-built tools that were part of Rules in D7. But because these tools are now in core, Rules does not need to provide them anymore.

In particular, the core Configuration Manager module allows you to import and export configurations, so Rules no longer has explicit import and export functions in the UI because these operations are now handled by core.

However, for someone using the Rules UI who might not be aware of the details of the implementation of Rules, it appears this functionality has just disappeared.

So to make the UI easier to use, here's a patch adding shortcut action links to the import and export functionality. These shortcuts appear on the Reaction Rules admin form and on the Rules Components admin form. They require that the core Configuration Manager module be enabled, so that has been added as a dependency for this module. I believe in most profiles the core Configuration Manager is already enabled by default.

Comments

TR created an issue. See original summary.

tr’s picture

Status: Active » Needs review
Issue tags: +D8RE
StatusFileSize
new1.24 KB
tree2009’s picture

Status: Needs review » Reviewed & tested by the community

  • TR committed 347af12 on 8.x-3.x
    Issue #3162798 by TR: Add shortcuts to import/export Rules
    
tr’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

jonathan1055’s picture

Status: Fixed » Needs review
StatusFileSize
new790 bytes

I've been using these shortcut links from D8RE for ages, thanks for moving them to Rules.

I have also found it very useful, after importing or exporting a rule, to have a quick way to get back to Rules, so I added return buttons in my own custom module. Now that the main buttons are in Rules you may like to add these too.

tr’s picture

Yes, that sounds useful, but I don't want to contaminate a core administration page with Rules-specific stuff for everyone to see every time they visit that page. Is there a way instead to append a ?destination= argument when clicking on the action link on the Rules page, that way when the config import/export form is submitted it will redirect back?

jonathan1055’s picture

You are right that its not good to have those buttons there every time, just because Rules is installed. Yes some ?destination parameter to return to the Rules page after the import/export would be exactly right. Not sure how tricky it will be, as the form has the secondary step 'confirm', which would also need to know about the return destination. Definitely worth trying.

tr’s picture

StatusFileSize
new1.45 KB

The first Drupal 8 release was more than 7 years ago. Yet I defy anyone to show me documentation on drupal.org, either API documentation or other core documentation, which describes the keys available for use in *.links.action.yml, let alone describes how to use these keys. This is just one example of the total failure of Drupal to provide basic documentation for its foundational core APIs.

But here's a secret - the *.links.action.yml file accepts TWO undocumented keys, 'route_parameters' and 'options'. Core never uses these anywhere, so there are no examples. And these are not described in the hook documentation for altering local actions, nor in the documentation for *.links.action.yml, nor in the documentation for LocalAction or LocalActionManager, or anywhere else I have found. You just have to know that *.links.action.yml holds YML annotation for discovery of LocalAction type plugins, and then you have to read the code. Just like many things in Drupal.

For this issue, we can use the undocumented 'options' key to put the destination into the *.links.action.yml file like this:

# Shortcut to import Reaction Rule / Rules Component.
rules_import_action:
  route_name: config.import_single
  options:
    query:
      - destination: admin/config/workflow/rules
  title: 'Import rule'
  appears_on:
    - entity.rules_reaction_rule.collection
    - entity.rules_component.collection

In the attached patch I split this up and create separate actions for the Reaction Rule list builder and the Rules Component list builder so they don't redirect back to the same place.

Regardless, this seems to work the way we want it for the import case, even with the confirm form in the way. For the export case, the export form doesn't have any button, so there's never any action to trigger the redirect.

tr’s picture

StatusFileSize
new1.94 KB

Rearranging the lines - I think it's more readable to list the title first. This patch is otherwise identical to #9.

jonathan1055’s picture

Well, that's great detective work! Thanks.

Tested patch #10 and confirm that after import I was returned back to the Rules list page.

For export, yes there is no submit button, that's a shame. The destination is still shown on the url
admin/config/development/configuration/single/export?destination=admin/config/workflow/rules so is it possible to use the presence of that in a Rules hook_form_altar to add a button to return back?

jonathan1055’s picture

Just tried this in hook_form_alter()

  if ($form['#id'] == 'config-single-export-form'
    && strpos(\Drupal::service('redirect.destination')->getAsArray()['destination'], 'config/workflow/rules')) {
    $form['return_to_rules'] = [
      '#type' => 'submit',
      '#value' => t('Return to Rules'),
      '#submit' => [],
      '#validate' => [],
    ];
  }

It works on first press if you have not selected anything to export. But if you have picked an item, then the first press of the button stays on the form, and the second press takes you back to the Rules page. I am sure there is a simple way to solve this.

Also the

tr’s picture

I feel this is really a problem with the core Configuration Export page, as the UI for that has always been very strange - it outputs the exported configuration in a textarea, and presents a description of what you should name the file if you cut/paste the contents of that textarea. Not sure why cut/paste is the preferred (and only) form of "export" here, as cut/paste should really only be a fallback / last resort for dealing with bulk data.

I don't know what the use case for the current page is, but I think it would be much better if there were a download button which would initiate a download when you selected a configuration to export (and BTW would set the file name appropriately for you ...). This could be in addition to the textarea OR as a replacement for the textarea, but I don't see how the cut/paste model is useful, other than to inspect the contents of the config - but that use case is not really related to "exporting" configuration, and that use case is better handled by the Config Inspector module.

So I think maybe we should just commit #10 without trying to redirect back from the export page, but we should also open up a core issue with a proposal to fix the config export page to be something more useful. Then after core is fixed we can patch Rules to redirect back from that more-useful export page since it will now have a button.

jonathan1055’s picture

Status: Needs review » Reviewed & tested by the community

... problem with the core Configuration Export page, as the UI for that has always been very strange

Yes it is

So I think maybe we should just commit #10 without trying to redirect back from the export page,

Agreed.

open up a core issue with a proposal to fix the config export page to be something more useful.

Yes, your idea of having a download button, which also has the name pre-filled, is a more helpful way to do it. I also had the same idea.

after core is fixed we can patch Rules to redirect back

With any luck we won't need to patch, as the destination will already be set with this commit. Obviously it depends on the the exact UI process implemented.

RTBC for patch #10

tr’s picture

Issue summary: View changes

Updated issue summary.

  • TR committed d6a91b1 on 8.x-3.x
    Issue #3162798 by TR, jonathan1055: Add shortcuts to import/export Rules
    
tr’s picture

Status: Reviewed & tested by the community » Fixed

With any luck we won't need to patch, as the destination will already be set with this commit. Obviously it depends on the the exact UI process implemented

Oh, that's true isn't it. OK, that's even better.

Committed #10.

Status: Fixed » Closed (fixed)

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