Skip to content

Commit

Permalink
Update Conditions to support PHP Attributes (eileenmcnaughton#498)
Browse files Browse the repository at this point in the history
Co-authored-by: Rafał Dziubak <[email protected]>
  • Loading branch information
2 people authored and puresyntax71 committed Jan 9, 2025
1 parent e5be262 commit a29e6bf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Plugin/Condition/ContactInGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

use Drupal\civicrm_entity\CiviCrmApi;
use Drupal\civicrm_entity\Entity\CivicrmEntity;
use Drupal\civicrm_entity\TypedData\Options\CivicrmGroupOptions;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\rules\Context\ContextDefinition;
use Drupal\rules\Core\RulesConditionBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\rules\Core\Attribute\Condition;

/**
* Provides a 'CiviCRM Contact in Group' condition.
Expand All @@ -31,6 +35,27 @@
* }
* )
*/
#[Condition(
id: "civicrm_entity_contact_in_group",
label: new TranslatableMarkup("CiviCRM Contact in Group"),
category: new TranslatableMarkup("CiviCRM"),
context_definitions: [
"civicrm_contact" => new ContextDefinition(
data_type: "entity:civicrm_contact",
label: new TranslatableMarkup("CiviCRM contact entity"),
required: TRUE,
description: new TranslatableMarkup("The CiviCRM contact entity.")
),
"group" => new ContextDefinition(
data_type: "string",
label: new TranslatableMarkup("Group"),
required: TRUE,
multiple: FALSE,
description: new TranslatableMarkup("The group the contact is in."),
options_provider: CivicrmGroupOptions::class,
),
]
)]
class ContactInGroup extends RulesConditionBase implements ContainerFactoryPluginInterface {

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Plugin/Condition/DrupalUserExist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Drupal\civicrm_entity\Plugin\Condition;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\rules\Context\ContextDefinition;
use Drupal\rules\Core\Attribute\Condition;
use Drupal\rules\Core\RulesConditionBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
Expand All @@ -25,6 +28,19 @@
* }
* )
*/
#[Condition(
id: "civicrm_entity_drupal_user_exists",
label: new TranslatableMarkup("CiviCRM Contact linked User exists"),
category: new TranslatableMarkup("CiviCRM"),
context_definitions: [
"civicrm_contact" => new ContextDefinition(
data_type: "entity:civicrm_contact",
label: new TranslatableMarkup("CiviCRM contact entity"),
required: TRUE,
description: new TranslatableMarkup("The CiviCRM contact entity.")
),
]
)]
class DrupalUserExist extends RulesConditionBase implements ContainerFactoryPluginInterface {

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Plugin/Condition/DrupalUserExistsContactId.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Drupal\civicrm_entity\Plugin\Condition;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\rules\Context\ContextDefinition;
use Drupal\rules\Core\Attribute\Condition;
use Drupal\rules\Core\RulesConditionBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
Expand All @@ -24,6 +27,19 @@
* }
* )
*/
#[Condition(
id: "civicrm_contact_id_drupal_user_exists",
label: new TranslatableMarkup("CiviCRM Contact Id linked User exists"),
category: new TranslatableMarkup("CiviCRM"),
context_definitions: [
"civicrm_contact_id" => new ContextDefinition(
data_type: "integer",
label: new TranslatableMarkup("CiviCRM contact ID"),
required: TRUE,
description: new TranslatableMarkup("The CiviCRM contact ID.")
),
]
)]
class DrupalUserExistsContactId extends RulesConditionBase implements ContainerFactoryPluginInterface {

/**
Expand Down

0 comments on commit a29e6bf

Please sign in to comment.