From 018ae2ab3ab92dd3adf66c81447771bba8da62cc Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Tue, 18 Jul 2023 15:15:17 +0200 Subject: [PATCH 1/3] Dispatch an event for modifying the connector ID --- src/CiviMRF.php | 18 ++++++++++++++---- src/Event/ConnectorEvent.php | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/Event/ConnectorEvent.php diff --git a/src/CiviMRF.php b/src/CiviMRF.php index 4fdfec5..9c840dc 100644 --- a/src/CiviMRF.php +++ b/src/CiviMRF.php @@ -15,9 +15,10 @@ namespace Drupal\civiremote; - use Drupal; use Drupal\cmrf_core\Core; +use Drupal\civiremote\Event\ConnectorEvent; +use \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher; /** * Class CiviMRF @@ -26,15 +27,24 @@ */ class CiviMRF { - /** @var Core */ + /** + * @var Core + */ public $core; public function __construct(Core $core) { $this->core = $core; } - protected function connector() { - return Drupal::config('civiremote.settings')->get('cmrf_connector'); + protected function connector(array $context = []) { + $event = new ConnectorEvent( + Drupal::config('civiremote.settings')->get('cmrf_connector'), + $context + ); + /* @var ContainerAwareEventDispatcher $event_dispatcher */ + $event_dispatcher = \Drupal::service('event_dispatcher'); + $event_dispatcher->dispatch($event, ConnectorEvent::EVENT_NAME); + return $event->getConnectorId(); } /** diff --git a/src/Event/ConnectorEvent.php b/src/Event/ConnectorEvent.php new file mode 100644 index 0000000..eec8a05 --- /dev/null +++ b/src/Event/ConnectorEvent.php @@ -0,0 +1,37 @@ +connector_id = $connector_id; + $this->context = $context; + } + + /** + * @return string + */ + public function getConnectorId(): string { + return $this->connector_id; + } + +} From 24ee8002f78019fba5b39b8561db009925ab1d3e Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Tue, 18 Jul 2023 15:35:01 +0200 Subject: [PATCH 2/3] Provide default context for ConnectorEvent --- modules/civiremote_event/src/CiviMRF.php | 24 ++++++---------- src/CiviMRF.php | 35 +++++++++++++++++++++--- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/modules/civiremote_event/src/CiviMRF.php b/modules/civiremote_event/src/CiviMRF.php index ac1f4f8..9c58dae 100644 --- a/modules/civiremote_event/src/CiviMRF.php +++ b/modules/civiremote_event/src/CiviMRF.php @@ -55,8 +55,7 @@ public function getEvent($event_id, $remote_token = NULL) { $reply = &drupal_static(__FUNCTION__ . '_' . implode('_', $params)); if (!isset($reply)) { - $call = $this->core->createCall( - $this->connector(), + $call = $this->createCall( 'RemoteEvent', 'getsingle', $params, @@ -106,8 +105,7 @@ public function getForm($event_id, $profile, $remote_token = NULL, $context = 'c $reply = &drupal_static(__FUNCTION__ . '_' . implode('_', $params)); if (!isset($reply)) { - $call = $this->core->createCall( - $this->connector(), + $call = $this->createCall( 'RemoteParticipant', 'get_form', $params, @@ -155,8 +153,7 @@ public function validateEventRegistration($event_id, $profile, $remote_token = N 'context' => $context, ]); self::addRemoteContactId($params); - $call = $this->core->createCall( - $this->connector(), + $call = $this->createCall( 'RemoteParticipant', 'validate', $params, @@ -197,8 +194,7 @@ public function createEventRegistration($event_id, $profile, $remote_token = NUL 'token' => $remote_token ]); self::addRemoteContactId($params); - $call = $this->core->createCall( - $this->connector(), + $call = $this->createCall( 'RemoteParticipant', 'create', $params, @@ -242,8 +238,7 @@ public function updateEventRegistration($event_id, $profile, $remote_token = NUL 'token' => $remote_token ]); self::addRemoteContactId($params); - $call = $this->core->createCall( - $this->connector(), + $call = $this->createCall( 'RemoteParticipant', 'update', $params, @@ -282,8 +277,7 @@ public function cancelEventRegistration($event_id, $remote_token = NULL, $show_m 'token' => $remote_token ]; self::addRemoteContactId($params); - $call = $this->core->createCall( - $this->connector(), + $call = $this->createCall( 'RemoteParticipant', 'cancel', $params, @@ -323,8 +317,7 @@ public function getCheckinInfo($remote_token, $show_messages = FALSE) { 'token' => $remote_token ]; self::addRemoteContactId($params); - $call = $this->core->createCall( - $this->connector(), + $call = $this->createCall( 'EventCheckin', 'verify', $params, @@ -370,8 +363,7 @@ public function checkinParticipant($remote_token, $status_id, $show_messages = F 'status_id' => $status_id, ]; self::addRemoteContactId($params); - $call = $this->core->createCall( - $this->connector(), + $call = $this->createCall( 'EventCheckin', 'confirm', $params, diff --git a/src/CiviMRF.php b/src/CiviMRF.php index 9c840dc..3ec32f2 100644 --- a/src/CiviMRF.php +++ b/src/CiviMRF.php @@ -47,6 +47,35 @@ protected function connector(array $context = []) { return $event->getConnectorId(); } + /** + * @param $entity + * @param $action + * @param $params + * @param $options + * @param $callback + * @param $api_version + * + * @return \CMRF\Core\Call + */ + protected function createCall($entity, $action, $params = [], $options = [], $callback = NULL, $api_version = '3') { + return $this->core->createCall( + $this->connector([ + 'entity' => $entity, + 'action' => $action, + 'params' => $params, + 'options' => $options, + 'callback' => $callback, + 'api_version' => $api_version, + ]), + $entity, + $action, + $params, + $options, + $callback, + $api_version + ); + } + /** * @param $params * @@ -54,8 +83,7 @@ protected function connector(array $context = []) { * The CiviRemote ID, or FALSE when no contact could be matched. */ public function matchContact($params) { - $call = $this->core->createCall( - $this->connector(), + $call = $this->createCall( 'RemoteContact', 'match', $params, @@ -73,8 +101,7 @@ public function matchContact($params) { * The CiviRemote roles, or FALSE when synchronising roles failed. */ public function getRoles($params) { - $call = $this->core->createCall( - $this->connector(), + $call = $this->createCall( 'RemoteContact', 'get_roles', $params, From d9e92aec8b099c15c50b412c74c69beb19a98d98 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Thu, 14 Sep 2023 13:34:54 +0200 Subject: [PATCH 3/3] Add setter for connector ID in ConnectorEvent --- src/Event/ConnectorEvent.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Event/ConnectorEvent.php b/src/Event/ConnectorEvent.php index eec8a05..b253095 100644 --- a/src/Event/ConnectorEvent.php +++ b/src/Event/ConnectorEvent.php @@ -34,4 +34,13 @@ public function getConnectorId(): string { return $this->connector_id; } + /** + * @param string $connector_id + * + * @return void + */ + public function setConnectorId(string $connector_id): void { + $this->connector_id = $connector_id; + } + }