diff --git a/includes/rules.core.inc b/includes/rules.core.inc index 2014e0e..0e98a0d 100644 --- a/includes/rules.core.inc +++ b/includes/rules.core.inc @@ -17,7 +17,18 @@ require_once dirname(__FILE__) . '/faces.inc'; class RulesEntityController extends EntityAPIControllerExportable { /** - * Overriden. + * Overridden. + * + * @see EntityAPIController::create() + */ + public function create(array $values = array()) { + // Default to rules as owning module. + $values += array('owner' => 'rules'); + return parent::create($values); + } + + /** + * Overridden. * @see DrupalDefaultEntityController::attachLoad() */ protected function attachLoad(&$queried_entities, $revision_id = FALSE) { @@ -1079,7 +1090,15 @@ abstract class RulesPlugin extends RulesExtendable { $this->plugin = $this->itemName; $this->name = isset($name) ? $name : $this->name; + // Module stores the module via which the rule is configured and is used + // for generating machine names with the right prefix. However, for + // default configurations 'module' points to the module providing the + // default configuration, so the module via which the rules is configured + // is stored in the "owner" property. + // @todo: For Drupal 8 use "owner" for generating machine names also and + // module only for the modules providing default configurations. $this->module = !isset($this->module) || $module != 'rules' ? $module : $this->module; + $this->owner = !isset($this->owner) || $module != 'rules' ? $module : $this->owner; $this->ensureNameExists(); $this->data = $this; $return = entity_get_controller('rules_config')->save($this); @@ -1135,7 +1154,9 @@ abstract class RulesPlugin extends RulesExtendable { // Keep the id always as we need it for the recursion prevention. $array = drupal_map_assoc(array('parent', 'id', 'elementId', 'weight', 'settings')); // Keep properties related to configurations if they are there. - foreach (array('name', 'module', 'status', 'label', 'recursion', 'tags') as $key) { + $info = entity_get_info('rules_config'); + $fields = array_merge($info['schema_fields_sql']['base table'], array('recursion', 'tags')); + foreach ($fields as $key) { if (isset($this->$key)) { $array[$key] = $key; } diff --git a/rules.api.php b/rules.api.php index 3905692..e672117 100644 --- a/rules.api.php +++ b/rules.api.php @@ -712,7 +712,7 @@ function hook_rules_config_insert($config) { * The rules configuration that is being inserted or updated. */ function hook_rules_config_presave($config) { - if ($config->id && $config->module == 'yours') { + if ($config->id && $config->owner == 'your_module') { // Add custom condition. $config->conditon(/* Your condition */); } diff --git a/rules.install b/rules.install index c27dd68..b91e94b 100644 --- a/rules.install +++ b/rules.install @@ -87,6 +87,13 @@ function rules_schema() { 'length' => 255, 'not null' => FALSE, ), + 'owner' => array( + 'description' => 'The name of the module via which the rule has been configured.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => 'rules', + ), 'access_exposed' => array( 'type' => 'int', 'not null' => TRUE, @@ -447,3 +454,17 @@ function rules_update_7209() { function rules_update_7210() { variable_del('rules_empty_sets'); } + +/** + * Creates the "owner" column. + */ +function rules_update_7211() { + // Create a owner column. + db_add_field('rules_config', 'owner', array( + 'description' => 'The name of the module via which the rule has been configured.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => 'rules', + )); +} diff --git a/ui/ui.controller.inc b/ui/ui.controller.inc index fd86a95..af38f41 100644 --- a/ui/ui.controller.inc +++ b/ui/ui.controller.inc @@ -192,6 +192,10 @@ class RulesUIController { 'show events' => isset($conditions['plugin']) && $conditions['plugin'] == 'reaction rule', 'show execution op' => !(isset($conditions['plugin']) && $conditions['plugin'] == 'reaction rule'), ); + // By default show only configurations owned by rules. + $conditions += array( + 'owner' => 'rules', + ); if (!empty($options['base path'])) { RulesPluginUI::$basePath = $options['base path']; } diff --git a/ui/ui.core.inc b/ui/ui.core.inc index d202e34..163c0f8 100644 --- a/ui/ui.core.inc +++ b/ui/ui.core.inc @@ -420,6 +420,8 @@ class RulesPluginUI extends FacesExtender implements RulesPluginUIInterface { '#required' => TRUE, '#weight' => -5, ); + // @todo: For Drupal 8 use "owner" for generating machine names and + // module only for the modules providing default configurations. if (!empty($this->element->module) && !empty($this->element->name) && $this->element->module == 'rules' && strpos($this->element->name, 'rules_') === 0) { // Remove the Rules module prefix from the machine name. $machine_name = substr($this->element->name, strlen($this->element->module) + 1);