I'm trying to create a new plugin for Rules, mimicking much of the rule set plugin but altering a few things.

I keep getting a "FacesExtendableException" error, similar to the one reported at #1285856: FacesExtendableException : There is no method dependencies for this instance of the class RulesAction.
I assume that I'm declaring my plugin wrong, but I have a really hard time finding exhaustive documentation and/or examples. Thus, this is a feature request to complement the documentation on this.

(The existing docs page on this is found here: http://drupal.org/node/905552)

Comments

fago’s picture

Well, extenders are really an internal, complicated thing I'd love to scratch if I find time.. ;)

You basically just need to care about adding an UI extender. Have you read the docs of hook_rules_plugin_info()? I guess we should add a paragraph about how extenders are used in rules there.

itangalo’s picture

Yeah, I've read the doxygen docs too… :-/

I *might* be the case that I'm doing things right, and that I'm triggering the bug linked to above. But more likely I am not using the extenders correctly.

fago’s picture

What are you doing? Just past the code here and I'll have a look.

itangalo’s picture

What are you doing? Just past the code here and I'll have a look.

Damn, that's smart. (Or, rather, I'm pretty stupid not to include it to begin with…)

In rb_views.rules.inc

function rb_views_rules_plugin_info() {
  // Most of this is just copy-pasted from the rule set component.
  return array(
    'views argument validator' => array(
      'label' => t('Views argument validator'),
      'module' => 'rb_views',
      'class' => 'RbViewsArgumentValidator',
      'component' => TRUE,
      'embeddable' => FALSE,
      'extenders' => array(
        'RulesPluginUIInterface' => array(
          'class' => 'RbViewsArgumentValidatorUI',
        ),
      ),
    ),
  );
}

In rb_views.module

/**
 * Class defining the Views argument validator plugin.
 */
class RbViewsArgumentValidator extends RulesRuleSet {

  protected $itemName = 'views argument validator';

  /**
   * Override to set the provided and required variables to fixed sets.
   */
  public function __construct($variables = array(), $providesVars = array()) {
    // Set some fixed variables used by this type of plugin. (Editing of these
    // is disabled.)
    $variables = array(
      'arg' => array(
        'type' => 'text',
        'label' => t('Argument'),
      ),
      'args' => array(
        'type' => 'list<text>',
        'label' => t('All arguments'),
      ),
      'validation' => array(
        'type' => 'boolean',
        'label' => t('Validation value'),
        'parameter' => FALSE,
      ),
    );

    $providesVars = array('arg', 'args', 'validation');

    parent::__construct($variables);
    // The provided vars of a component are the names of variables, which should
    // be provided to the caller. See rule().
    if ($providesVars) {
      $this->info['provides'] = $providesVars;
    }
  }
}

/**
 * Class defining the UI for the Views argument validator plugin.
 */
class RbViewsArgumentValidatorUI extends RulesRuleSetUI {
  // Override form to hide the variables settings.
  public function form(&$form, &$form_state, $options = array(), $iterator = NULL) {
    parent::form($form, $form_state, $options, $this->element->getIterator());
    $form['settings']['vars']['#access'] = FALSE;
  }
}
patrickd’s picture

I got the same problems with my plugins,
does anybody have a guess ?

mitchell’s picture

Title: More documentation about 'extenders' property in hook_rules_plugin_info » Improve hook_rules_plugin_info documentation for 'extenders' property
Category: feature » task
Issue tags: +FAQ
tr’s picture

Issue summary: View changes
Status: Active » Postponed
Issue tags: -FAQ

Doesn't seem like there's much community interest in this ...

tr’s picture

Status: Postponed » Closed (won't fix)