diff --git a/config/schema/rules.schema.yml b/config/schema/rules.schema.yml index b42567a8ec9559c5d5136c720e9782d5ef8180ea..8b0b1a82d318387f01bd42a2c4f96bd3859a51ba 100644 --- a/config/schema/rules.schema.yml +++ b/config/schema/rules.schema.yml @@ -13,9 +13,12 @@ rules.component.*: description: type: text label: 'Administrative description' - tag: - type: string - label: 'Tag' + tags: + type: sequence + label: Tags + sequence: + type: string + label: 'Tag' config_version: type: string label: 'Configuration schema version' @@ -50,9 +53,12 @@ rules.reaction.*: description: type: text label: 'Administrative description' - tag: - type: string - label: 'Tag' + tags: + type: sequence + label: Tags + sequence: + type: string + label: 'Tag' config_version: type: string label: 'Configuration schema version' diff --git a/src/Controller/RulesReactionListBuilder.php b/src/Controller/RulesReactionListBuilder.php index 0f881bfe25ff02569741b52ee80b16f7f7b4a847..95aec014a7d694c4f59859e283fcb089e4af8908 100644 --- a/src/Controller/RulesReactionListBuilder.php +++ b/src/Controller/RulesReactionListBuilder.php @@ -29,7 +29,7 @@ class RulesReactionListBuilder extends ConfigEntityListBuilder { $header['id'] = $this->t('ID'); $header['label'] = $this->t('Label'); $header['description'] = $this->t('Description'); - $header['tag'] = $this->t('Tag'); + $header['tags'] = $this->t('Tags'); return $header + parent::buildHeader(); } @@ -41,7 +41,7 @@ class RulesReactionListBuilder extends ConfigEntityListBuilder { $row['id'] = $entity->id(); $row['label'] = $this->getLabel($entity); $row['description'] = $entity->getDescription(); - $row['tag'] = $entity->getTag(); + $row['tags'] = implode(', ', $entity->getTags()); return $row + parent::buildRow($entity); } diff --git a/src/Core/RulesEventManager.php b/src/Core/RulesEventManager.php index 647bd04a4d66691053042180dd7faf415d31d20c..304b08630ccaedf2dff6cac334b30895028ef772 100644 --- a/src/Core/RulesEventManager.php +++ b/src/Core/RulesEventManager.php @@ -49,7 +49,7 @@ class RulesEventManager extends DefaultPluginManager implements CategorizingPlug /** * {@inheritdoc} */ - public function createInstance($plugin_id, array $configuration = array()) { + public function createInstance($plugin_id, array $configuration = []) { // If a fully qualified event name is passed, be sure to get the base name // first. $plugin_id = $this->getEventBaseName($plugin_id); diff --git a/src/Engine/RulesComponent.php b/src/Engine/RulesComponent.php index a70d14362ad153dd4ab355f5fbf67cc731900e64..c5e08c789ffc435bc34bcea0ab93b1292c63b0a6 100644 --- a/src/Engine/RulesComponent.php +++ b/src/Engine/RulesComponent.php @@ -166,7 +166,7 @@ class RulesComponent { * * @param string[] $event_names * The (fully qualified) event names; e.g., as configured for a reaction - * rule. + * rule. * * @return $this */ diff --git a/src/Entity/ReactionRuleConfig.php b/src/Entity/ReactionRuleConfig.php index 69c2e168ae979188126ef540ef5e058e7042ea6b..58e55f8df3905c07bdef36b41a17df6d7f591cfe 100644 --- a/src/Entity/ReactionRuleConfig.php +++ b/src/Entity/ReactionRuleConfig.php @@ -40,7 +40,7 @@ use Drupal\rules\Engine\RulesComponent; * "label", * "events", * "description", - * "tag", + * "tags", * "config_version", * "expression", * }, @@ -78,12 +78,9 @@ class ReactionRuleConfig extends ConfigEntityBase implements RulesUiComponentPro /** * The "tags" of a Reaction rule. * - * The tags are stored as a single string, though it is used as multiple tags - * for example in the rules overview. - * - * @var string + * @var string[] */ - protected $tag = ''; + protected $tags = []; /** * The version the Reaction rule was created for. @@ -213,10 +210,13 @@ class ReactionRuleConfig extends ConfigEntityBase implements RulesUiComponentPro } /** - * Returns the tag. + * Returns the tags associated with this config. + * + * @return string[] + * The numerically indexed array of tag names. */ - public function getTag() { - return $this->tag; + public function getTags() { + return $this->tags; } /** @@ -251,13 +251,7 @@ class ReactionRuleConfig extends ConfigEntityBase implements RulesUiComponentPro */ public function calculateDependencies() { parent::calculateDependencies(); - - // Ensure that the Reaction rule is dependent on the module that - // implements the component. - $this->addDependency('module', $this->module); - - // @todo Handle dependencies of plugins that are provided by various modules - // here. + $this->addDependencies($this->getComponent()->calculateDependencies()); return $this->dependencies; } diff --git a/src/Entity/RulesComponentConfig.php b/src/Entity/RulesComponentConfig.php index 88936b0cde490bf163f4220610fb1ebd67e3e6a6..9ed51d941e2b369b6a9cbbd67750039b0dffdaaa 100644 --- a/src/Entity/RulesComponentConfig.php +++ b/src/Entity/RulesComponentConfig.php @@ -39,7 +39,7 @@ use Drupal\rules\Engine\RulesComponent; * "id", * "label", * "description", - * "tag", + * "tags", * "config_version", * "component", * }, @@ -76,12 +76,9 @@ class RulesComponentConfig extends ConfigEntityBase implements RulesUiComponentP /** * The "tags" of a Rules component. * - * The tags are stored as a single string, though it is used as multiple tags - * for example in the rules overview. - * - * @var string + * @var string[] */ - protected $tag = ''; + protected $tags = []; /** * The config version the Rules component was created for. @@ -242,10 +239,13 @@ class RulesComponentConfig extends ConfigEntityBase implements RulesUiComponentP } /** - * Returns the tag. + * Returns the tags associated with this config. + * + * @return string[] + * The numerically indexed array of tag names. */ - public function getTag() { - return $this->tag; + public function getTags() { + return $this->tags; } /** diff --git a/src/Form/RulesComponentFormBase.php b/src/Form/RulesComponentFormBase.php index ccb8c6dd671a7bec0ab0f3b8a31e0570ac615952..bededcde450d5a4d567e00fdd9577baf7dcdd718 100644 --- a/src/Form/RulesComponentFormBase.php +++ b/src/Form/RulesComponentFormBase.php @@ -46,11 +46,11 @@ abstract class RulesComponentFormBase extends EntityForm { ]; // @todo enter a real tag field here. - $form['settings']['tag'] = [ + $form['settings']['tags'] = [ '#type' => 'textfield', - '#title' => $this->t('Tag'), - '#default_value' => $this->entity->getTag(), - '#description' => $this->t('Enter a tag here'), + '#title' => $this->t('Tags'), + '#default_value' => implode(', ', $this->entity->getTags()), + '#description' => $this->t('Enter a list of comma-separated tags here; e.g., "notification, publishing".'), '#required' => FALSE, ]; @@ -64,6 +64,16 @@ abstract class RulesComponentFormBase extends EntityForm { return parent::form($form, $form_state); } + /** + * {@inheritdoc} + */ + public function buildEntity(array $form, FormStateInterface $form_state) { + $entity = parent::buildEntity($form, $form_state); + $tags = array_map('trim', explode(',', $entity->get('tags'))); + $entity->set('tags', $tags); + return $entity; + } + /** * Machine name exists callback. * diff --git a/tests/modules/rules_test_default_component/config/install/rules.component.rules_test_default_component.yml b/tests/modules/rules_test_default_component/config/install/rules.component.rules_test_default_component.yml index db4eced573d733efddfa74abdbb3f8ffa68be059..8095fe229e80bb0ecbb5d0419988b9a2bc3ad61d 100644 --- a/tests/modules/rules_test_default_component/config/install/rules.component.rules_test_default_component.yml +++ b/tests/modules/rules_test_default_component/config/install/rules.component.rules_test_default_component.yml @@ -4,8 +4,9 @@ dependencies: {} id: rules_test_default_component label: Rules test default component description: 'Tests adding Rules component by default.' -tag: 'test' -config_version: 3.0 +tags: + - 'test' +config_version: '3.0' component: context_definitions: user: