From e297c1ee2b5895804659662875717cc399e93c81 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Wed, 11 Nov 2020 15:30:39 +0100 Subject: [PATCH] [#4] Adjust API calls for changes in de.systopia.newsletter --- src/CiviMRF.php | 42 ++++++++++++++++++++++++++++++-- src/Routing/ProfileConverter.php | 2 +- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/CiviMRF.php b/src/CiviMRF.php index ee7af10..dd7c14a 100644 --- a/src/CiviMRF.php +++ b/src/CiviMRF.php @@ -64,7 +64,7 @@ protected function connector() { * The Advanced Newsletter Management profile configuration, or NULL if the * profile could not be retrieved. */ - public function profileGet($profile_name = NULL) { + public function profileGetSingle($profile_name = NULL) { $params = array(); if ($profile_name) { $params['name'] = $profile_name; @@ -73,7 +73,7 @@ public function profileGet($profile_name = NULL) { $call = $this->core->createCall( $this->connector(), 'NewsletterProfile', - 'get', + 'getsingle', $params, [] ); @@ -101,6 +101,44 @@ public function profileGet($profile_name = NULL) { return $return; } + /** + * Retrieves the configuration for all Advanced Newsletter Management profiles + * from CiviCRM. + * + * @return array + * An array of Advanced Newsletter Management profile configurations. + */ + public function profileGet() { + $params = array(); + try { + $call = $this->core->createCall( + $this->connector(), + 'NewsletterProfile', + 'get', + $params, + [] + ); + $this->core->executeCall($call); + $reply = $call->getReply(); + if ($reply['is_error'] == 1) { + $return = []; + } + else { + $return = $reply['values']; + } + } + catch (Exception $exception) { + $variables = Error::decodeException($exception); + Drupal::logger('civicrm_newsletter')->error( + '%type: @message in %function (line %line of %file).', + $variables + ); + $return = []; + } + + return $return; + } + /** * Retrieves the subscription status for a given contact hash. * diff --git a/src/Routing/ProfileConverter.php b/src/Routing/ProfileConverter.php index b3ba1cb..4ac2b93 100644 --- a/src/Routing/ProfileConverter.php +++ b/src/Routing/ProfileConverter.php @@ -46,7 +46,7 @@ public function __construct(CiviMRF $cmrf) { */ public function convert($value, $definition, $name, array $defaults) { try { - return (object) $this->cmrf->profileGet($value); + return (object) $this->cmrf->profileGetSingle($value); } catch (Exception $exception) { throw new NotFoundHttpException(); }