-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Brevo support and deprecate Sendinblue usage
- Loading branch information
1 parent
12d2df1
commit 4f1f543
Showing
20 changed files
with
861 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\FormBundle\Dynamic\Helper; | ||
|
||
use Brevo\Client\Api\ContactsApi; | ||
use Brevo\Client\Configuration; | ||
|
||
/** | ||
* @final | ||
* | ||
* @internal | ||
*/ | ||
class BrevoListSelect | ||
{ | ||
/** | ||
* @var ContactsApi|null | ||
*/ | ||
private $contactsApi; | ||
|
||
public function __construct(?string $apiKey) | ||
{ | ||
if (!$apiKey) { | ||
return; | ||
} | ||
|
||
$config = new Configuration(); | ||
$config->setApiKey('api-key', $apiKey); | ||
|
||
$this->contactsApi = new ContactsApi(null, $config); | ||
} | ||
|
||
/** | ||
* Returns array of Brevo lists of given account defined by the API key. | ||
* | ||
* @return mixed[] | ||
*/ | ||
public function getValues(): array | ||
{ | ||
if (!$this->contactsApi) { | ||
return []; | ||
} | ||
|
||
$limit = 50; | ||
$offset = 0; | ||
$total = null; | ||
$listObjects = []; | ||
|
||
do { | ||
$response = $this->contactsApi->getLists($limit, $offset); | ||
|
||
if (null === $total) { | ||
$total = $response->getCount(); | ||
} | ||
|
||
$newListObjects = $response->getLists(); | ||
if (0 === \count($newListObjects)) { | ||
break; | ||
} | ||
|
||
$listObjects = \array_merge($listObjects, $newListObjects); | ||
$offset += $limit; | ||
} while (\count($listObjects) < $total); | ||
|
||
$lists = []; | ||
|
||
foreach ($listObjects as $list) { | ||
$lists[] = [ | ||
'name' => $list['id'], | ||
'title' => $list['name'], | ||
]; | ||
} | ||
|
||
return $lists; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\FormBundle\Dynamic\Helper; | ||
|
||
use Brevo\Client\Api\TransactionalEmailsApi; | ||
use Brevo\Client\Configuration; | ||
|
||
/** | ||
* @final | ||
* | ||
* @internal | ||
*/ | ||
class BrevoMailTemplateSelect | ||
{ | ||
/** | ||
* @var TransactionalEmailsApi|null | ||
*/ | ||
private $transactionalEmailsApi; | ||
|
||
public function __construct(?string $apiKey) | ||
{ | ||
if (!$apiKey) { | ||
return; | ||
} | ||
|
||
$config = new Configuration(); | ||
$config->setApiKey('api-key', $apiKey); | ||
|
||
$this->transactionalEmailsApi = new TransactionalEmailsApi(null, $config); | ||
} | ||
|
||
/** | ||
* Returns array of Brevo mail templates of given account defined by the API key. | ||
* | ||
* @return mixed[] | ||
*/ | ||
public function getValues(): array | ||
{ | ||
if (!$this->transactionalEmailsApi) { | ||
return []; | ||
} | ||
|
||
$limit = 50; | ||
$offset = 0; | ||
$total = null; | ||
$mailTemplateObjects = []; | ||
|
||
do { | ||
$response = $this->transactionalEmailsApi->getSmtpTemplates(true, $limit, $offset); | ||
|
||
if (null === $total) { | ||
$total = $response->getCount(); | ||
} | ||
|
||
$newMailTemplateObjects = $response->getTemplates(); | ||
if (0 === \count($newMailTemplateObjects)) { | ||
break; | ||
} | ||
|
||
$mailTemplateObjects = \array_merge($mailTemplateObjects, $newMailTemplateObjects); | ||
$offset += $limit; | ||
} while (\count($mailTemplateObjects) < $total); | ||
|
||
$mailTemplates = []; | ||
|
||
foreach ($mailTemplateObjects as $template) { | ||
if (($template['tag'] ?? null) !== 'optin') { | ||
continue; | ||
} | ||
|
||
$mailTemplates[] = [ | ||
'name' => $template['id'], | ||
'title' => $template['name'], | ||
]; | ||
} | ||
|
||
return $mailTemplates; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
* @final | ||
* | ||
* @internal | ||
* | ||
* @deprecated | ||
*/ | ||
class SendinblueListSelect | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
* @final | ||
* | ||
* @internal | ||
* | ||
* @deprecated | ||
*/ | ||
class SendinblueMailTemplateSelect | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\FormBundle\Dynamic\Types; | ||
|
||
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeConfiguration; | ||
use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypeInterface; | ||
use Sulu\Bundle\FormBundle\Entity\FormField; | ||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType as TypeCheckboxType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
/** | ||
* The Brevo form field type. | ||
*/ | ||
class BrevoType implements FormFieldTypeInterface | ||
{ | ||
public function getConfiguration(): FormFieldTypeConfiguration | ||
{ | ||
return new FormFieldTypeConfiguration( | ||
'sulu_form.type.brevo', | ||
__DIR__ . '/../../Resources/config/form-fields/field_brevo.xml', | ||
'special' | ||
); | ||
} | ||
|
||
public function build(FormBuilderInterface $builder, FormField $field, string $locale, array $options): void | ||
{ | ||
$type = TypeCheckboxType::class; | ||
$builder->add($field->getKey(), $type, $options); | ||
} | ||
|
||
public function getDefaultValue(FormField $field, string $locale) | ||
{ | ||
return $field->getTranslation($locale)->getDefaultValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.