ソースを参照

integration newsletter (par terminé)

v1
Charly 3年前
コミット
94372d83eb
8個のファイルの変更208行の追加3行の削除
  1. +2
    -1
      composer.json
  2. +104
    -1
      composer.lock
  3. +1
    -0
      config/bundles.php
  4. +5
    -1
      config/routes.yaml
  5. +2
    -0
      config/services.yaml
  6. +39
    -0
      src/Controller/Frontend/NewsletterController.php
  7. +49
    -0
      src/Form/SubscribeNewsletterForm.php
  8. +6
    -0
      symfony.lock

+ 2
- 1
composer.json ファイルの表示

@@ -48,7 +48,8 @@
"symfony/webpack-encore-bundle": "^1.11",
"symfony/yaml": "5.2.*",
"twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0"
"twig/twig": "^2.12|^3.0",
"welp/mailchimp-bundle": "^1.3"
},
"require-dev": {
"symfony/browser-kit": "^5.2",

+ 104
- 1
composer.lock ファイルの表示

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4f261c49c4e3d64b08acfca7246f15bf",
"content-hash": "cbf5b29748de791afdf10053f057e933",
"packages": [
{
"name": "artgris/filemanager-bundle",
@@ -1777,6 +1777,54 @@
},
"time": "2021-01-08T14:18:52+00:00"
},
{
"name": "drewm/mailchimp-api",
"version": "v2.5.4",
"source": {
"type": "git",
"url": "https://github.com/drewm/mailchimp-api.git",
"reference": "c6cdfab4ca6ddbc3b260913470bd0a4a5cb84c7a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/drewm/mailchimp-api/zipball/c6cdfab4ca6ddbc3b260913470bd0a4a5cb84c7a",
"reference": "c6cdfab4ca6ddbc3b260913470bd0a4a5cb84c7a",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "7.0.*",
"vlucas/phpdotenv": "^2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"DrewM\\MailChimp\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Drew McLellan",
"email": "drew.mclellan@gmail.com",
"homepage": "http://allinthehead.com/"
}
],
"description": "Super-simple, minimum abstraction MailChimp API v3 wrapper",
"homepage": "https://github.com/drewm/mailchimp-api",
"support": {
"issues": "https://github.com/drewm/mailchimp-api/issues",
"source": "https://github.com/drewm/mailchimp-api/tree/master"
},
"time": "2019-08-06T09:24:58+00:00"
},
{
"name": "easycorp/easyadmin-bundle",
"version": "v3.5.7",
@@ -8931,6 +8979,61 @@
"source": "https://github.com/webmozarts/assert/tree/1.10.0"
},
"time": "2021-03-09T10:59:23+00:00"
},
{
"name": "welp/mailchimp-bundle",
"version": "1.3.2",
"source": {
"type": "git",
"url": "https://github.com/welpdev/mailchimp-bundle.git",
"reference": "a26617b03f02e5bee1061c63cc5b30c1e9719989"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/welpdev/mailchimp-bundle/zipball/a26617b03f02e5bee1061c63cc5b30c1e9719989",
"reference": "a26617b03f02e5bee1061c63cc5b30c1e9719989",
"shasum": ""
},
"require": {
"drewm/mailchimp-api": "2.5.*",
"php": ">=5.6"
},
"require-dev": {
"phpspec/phpspec": "~2@dev",
"phpunit/phpunit": "~5",
"symfony/symfony": ">=2.7"
},
"type": "symfony-bundle",
"autoload": {
"psr-4": {
"Welp\\MailchimpBundle\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Titouan BENOIT",
"email": "titouan@welp.today"
}
],
"description": "MailChimp API V3 Symfony Bundle",
"homepage": "https://github.com/welpdev/mailchimp-bundle",
"keywords": [
"api",
"mailchimp",
"subscriber",
"symfony",
"user",
"v3"
],
"support": {
"issues": "https://github.com/welpdev/mailchimp-bundle/issues",
"source": "https://github.com/welpdev/mailchimp-bundle/tree/1.3.2"
},
"time": "2021-08-06T15:16:21+00:00"
}
],
"packages-dev": [

+ 1
- 0
config/bundles.php ファイルの表示

@@ -20,4 +20,5 @@ return [
Lc\SovBundle\LcSovBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => ['all' => true],
Welp\MailchimpBundle\WelpMailchimpBundle::class => ['all' => true],
];

+ 5
- 1
config/routes.yaml ファイルの表示

@@ -56,4 +56,8 @@ app_about:

app_contribuate:
path: /contribution-individuel
controller: App\Controller\Frontend\ContribuateController::contribuate
controller: App\Controller\Frontend\ContribuateController::contribuate

app_newsletter_subscribe:
path: /newsletter/inscription
controller: App\Controller\Frontend\NewsletterController::subscribeNewsletter

+ 2
- 0
config/services.yaml ファイルの表示

@@ -33,3 +33,5 @@ services:
resource: '../src/Controller/'
tags: ['controller.service_arguments']

welp_mailchimp:
api_key: 86a597a26c06a1896fe0adc58d1e8aef-us2

+ 39
- 0
src/Controller/Frontend/NewsletterController.php ファイルの表示

@@ -0,0 +1,39 @@
<?php

namespace App\Controller\Frontend;


use App\Form\SubscribeNewsletterForm;
use Symfony\Component\HttpFoundation\Request;
use Welp\MailchimpBundle\Exception\MailchimpException;
use Welp\MailchimpBundle\Event\SubscriberEvent;
use Welp\MailchimpBundle\Subscriber\Subscriber;

class NewsletterController extends DefaultController
{
public function subscribeNewsletter(Request $request)
{
$form = $this->createForm(SubscribeNewsletterForm::class) ;
$form->handleRequest($request) ;

if($form->isSubmitted() && $form->isValid()) {
$data = $form->getData() ;
$email = $data['email'] ;

try {
// api mailchimp
$subscriber = new Subscriber($email);
$this->container->get('event_dispatcher')->dispatch(
SubscriberEvent::EVENT_SUBSCRIBE,
new SubscriberEvent('91a235f34c', $subscriber)
);
$this->addFlash('success', 'Votre inscription à notre newsletter a bien été prise en compte.');
}
catch(MailchimpException $exception) {
$this->addFlash('error', $exception->getMessage());
}
}

return $this->redirectToRoute('home') ;
}
}

+ 49
- 0
src/Form/SubscribeNewsletterForm.php ファイルの表示

@@ -0,0 +1,49 @@
<?php

namespace App\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class SubscribeNewsletterForm extends AbstractType
{

/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('email', EmailType::class, [
'label' => 'Email',
'attr' => [
'placeholder' => 'Email'
]
]);
}

/**
* @param OptionsResolver $resolver
*/
public function setDefaultOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[

]
);
}

/**
* @return string
*/
public function getName()
{
return 'subscribe_newsletter';
}

}

+ 6
- 0
symfony.lock ファイルの表示

@@ -94,6 +94,9 @@
"dompdf/dompdf": {
"version": "v1.0.2"
},
"drewm/mailchimp-api": {
"version": "v2.5.4"
},
"easycorp/easyadmin-bundle": {
"version": "3.0",
"recipe": {
@@ -623,5 +626,8 @@
},
"webmozart/assert": {
"version": "1.10.0"
},
"welp/mailchimp-bundle": {
"version": "1.3.2"
}
}

読み込み中…
キャンセル
保存