Example #1
0
 public function client()
 {
     if ($this->client == null) {
         $apiKey = $this->configManager->get(self::API_KEY_SETTING);
         if (!$apiKey) {
             throw new \Exception('No MailChimp api key found, please enter your api key in admin › configuration');
         }
         $this->client = new MailChimp($apiKey);
     }
     return $this->client;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $forms = $this->registry->getForms();
     /** @var ConfigurationFormTypeInterface $form */
     foreach ($forms as $name => $form) {
         $builder->add($name, get_class($form), ['label' => $form->getLabel(), 'data' => $this->configManager->keyValues()]);
         $builder->get($name)->addModelTransformer(new CallbackTransformer(function ($original) {
             $transformed = [];
             foreach ($original as $key => $object) {
                 $transformed[$key] = $object->Value;
             }
             return $transformed;
         }, function ($submitted) {
             $transformed = [];
             foreach ($submitted as $key => $value) {
                 $object = new \stdClass();
                 $object->Value = $value;
                 $transformed[$key] = $object;
             }
             return $transformed;
         }));
     }
 }