When you browse to a Rules edit form, you lose the breadcrumb trail that you have at admin/config/workflow/rules which makes navigation a little more difficult (at least for me). In the Commerce UI I had to add a function to set the breadcrumb and called it from the page callback for the various menu items... which might be problematic here b/c it looks like you're calling drupal_get_form() directly. I don't think a form builder function should be fiddling with breadcrumbs, so it seems like I'd have to add wrapper callbacks for these forms and set the breadcrumb from there. What do you think? I'm happy to do this if you like the idea.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

Component: User Interface » User interface
Category: feature » task

Yep, we definitely need to solve this. The problem is that the path for editing a rules configuration is used from inside the "reaction rules" and the "components" tab, additionally I thought of allowing modules to re-use that paths too - such that modules integrating some rules UI don't have to re-implement all the menu callbacks.

So I'm unsure what's the right way to proceed, but maybe we just autogenerate the default breadcrumbs of Rules + add a hook "rules_ui_context_alter" that allows modules to alter the breadcrumb before it gets set based upon the Rules-configuration. That way a module could take over the rule-editing context for some configurations.

rszrama’s picture

Ooooh, I see. Yeah, allowing modules to re-use the same paths would be problematic for setting an appropriate breadcrumb. : D

In that regard, you could have some sort of hook that allows modules to specify the altered context, or you could just force them to use their own menu callbacks to embed the forms. Wondering if it would be easier to make a hook that allows for altering breadcrumbs or easier to make a hook that allows for embedding the whole edit UI at a different location (i.e. generate the menu items for the user... ahh... but then how would we know the breadcrumb)...

Thinking.

dasjo’s picture

subscribing

klausi’s picture

Status: Active » Needs review
FileSize
27.06 KB

Here is an attempt to solve the bread crumb issue and to decouple Rules and Rules Admin in a better way.
The idea: Use a static variable "basePath" in RulesPluginUI that indicates a base path of an overview page (e.g. admin/config/rules/reaction or admin/config/rules/components). The base path is passed via the hook_menu() implementation and preserved in $form_state, so that it is not lost on cached forms.

Furthermore this patch removes all path constants like RULES_UI_PATH from the UI files in Rules core, so that all third party modules can use the UI independently.
And this patch introduces a RulesUIController to make use of the Entity admin UI, currently only for specifying the hook_menu() items.

So ideally third party modules can embed the Rules UI like this:

/**
 * Implements hook_menu().
 */
function mymodule_menu() {
  $items = array();
  $items['admin/config/mymodule'] = array(
    'title' => 'My module',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('mymodule_rules_overview'),
    'access arguments' => array('administer rules'),
  );
  $controller = new RulesUIController();
  $items += $controller->config_menu('admin/config/mymodule');
  return $items;
}

function mymodule_rules_overview($form, $form_state) {
  form_load_include($form_state, 'inc', 'rules', 'ui/ui.forms');
  RulesPluginUI::$basePath = 'admin/config/mymodule';
  $form['table'] = RulesPluginUI::overviewTable();
  return $form;
}

Status: Needs review » Needs work

The last submitted patch, 904978-rules-base-path.patch, failed testing.

fago’s picture

great progress!

+ * The base path determines where the Rules overview UI lives. All forms that
+ * want to display Rules (overview) forms need to set this variable. This is
+ * necessary in order to get correct operation links, paths, redirects, bread
+ * crumbs etc.

Hm, it tells us where *an* overview UI lives, thus where we need to be able to edit the rules configs. I think we need to make this clearer, such that people don't think the base_path will also generate the overview page for them.

$form['#after_build'][] = 'rules_base_path_handler';

The name of the handler should reflect which kind of handler it is. E.g. use rules_form_after_build_restore_base_path().

klausi’s picture

Status: Needs work » Needs review
FileSize
27.67 KB

New patch:
* Tried to improve the $basePath comment, but it is not really satisfying yet.
* Renamed the form after build function.
* Removed all path constants. Now also the forms in rules_admin.inc are base path agnostic and get an additional $base_path parameter ==> better re-use for other modules.

fago’s picture

Awesome!

+    // Components UI menu entries

Missing trailing point.

rszrama’s picture

This is brilliant - exactly what I've been waiting for. : )

klausi’s picture

FileSize
31.78 KB

* Fixed the comment with the missing trailing point.
* Incorporated the changes from #990514: Porting Scheduler UI, rules_scheduler keeps its own hook_menu() for the schedule tab; the menu callback for manual scheduling is added to the RulesUIController.

fago’s picture

Status: Needs review » Fixed

Patch looks good + works great for me -> committed! Thanks!
Finally we have breadcrumbs.. yay :)

@rszrama: You'll have to update the DC rules UI stuff to add in rules-config menu items and to set the static path as outlined in #4. Please report if you ran into any troubles. :)

rszrama’s picture

Works like a charm! In case it helps to have another example, here's how I'm embedding the Rules UI at a URL specific to our payment settings. All our custom overview page does is categorize them by enabled and disabled with no filter form, so I didn't need as much as the example in #4:

Menu item definition:

  // Payment method Rules administration page.
  $items['admin/commerce/config/payment'] = array(
    'title' => 'Payment settings',
    'description' => 'Enable and configure payment method rule configurations.',
    'page callback' => 'commerce_payment_ui_admin_page',
    'access arguments' => array('administer payments'),
    'file' => 'includes/commerce_payment_ui.admin.inc',
  );
  
  // Add the menu items for the various Rules forms.
  $controller = new RulesUIController();
  $items += $controller->config_menu('admin/commerce/config/payment');

Page callback:

/**
 * Builds the payment settings page using the Rules UI overview table filtered
 *   to display payment method rules.
 */
function commerce_payment_ui_admin_page() {
  RulesPluginUI::$basePath = 'admin/commerce/config/payment';

  $content['enabled']['title']['#markup'] = '<h3>' . t('Enabled payment rules') . '</h3>';

  $conditions = array('event' => 'commerce_payment_methods', 'plugin' => 'reaction rule', 'active' => TRUE);
  $content['enabled']['rules'] = RulesPluginUI::overviewTable($conditions);
  $content['enabled']['rules']['#empty'] = t('There are no active payment methods.');

  $content['disabled']['title']['#markup'] = '<h3>' . t('Disabled payment rules') . '</h3>';

  $conditions['active'] = FALSE;
  $content['disabled']['rules'] = RulesPluginUI::overviewTable($conditions);
  $content['disabled']['rules']['#empty'] = t('There are no disabled payment methods.');

  return $content;
}

Status: Fixed » Closed (fixed)

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

fago’s picture

see #1015872: support contrib UIs even if rules_admin is disabled for a follow-up on that. The above approach of re-using the UI should still work, I tried to make it even easier though.