Skip to content

Commit

Permalink
Twig
Browse files Browse the repository at this point in the history
  • Loading branch information
betd-bmabille committed Sep 28, 2021
1 parent 5aaa9d8 commit 04a1d76
Show file tree
Hide file tree
Showing 243 changed files with 162 additions and 45,438 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ DATABASE_URL="mysql://gandalf:frodon@db:3306/mordor?serverVersion=5.7"
# Delivery is disabled by default via "null://localhost"
MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###

APP_MAIL_SENDTO=
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
APP_MAIL_SENDTO=
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ build: ## Build docker
printf "\033[32m Deploy to Server \033[0m\n"
$(DOCKER_COMPOSE) build

start: build ## Run project
run: build ## Run project
printf " 🏃\033[33m Running application ... \033[0m\n"
$(DOCKER_COMPOSE) pull
$(DOCKER_COMPOSE) up -d
Expand All @@ -69,6 +69,8 @@ stop: ## Stop the VMs
$(DOCKER_COMPOSE) stop
printf "\n\n"

start: run vendor assets ## Run project

##.env.dist => .env.local CP

##
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
"symfony/serializer": "5.3.*",
"symfony/string": "5.3.*",
"symfony/swiftmailer-bundle": "^3.5",
"symfony/templating": "5.3.*",
"symfony/translation": "5.3.*",
"symfony/twig-bundle": "5.3.*",
"symfony/validator": "5.3.*",
"symfony/web-link": "5.3.*",
"symfony/webpack-encore-bundle": "^1.12",
"symfony/yaml": "5.3.*",
"twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0",
"ext-http": "*"
"twig/twig": "^2.12|^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
Expand Down
71 changes: 69 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/packages/twig.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
twig:
default_path: '%kernel.project_dir%/templates'
form_themes: ['form/theme/custom.html.twig']

when@test:
twig:
Expand Down
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
app.mail.sendto: '%env(APP_MAIL_SENDTO)%'

services:
# default configuration for services in *this* file
Expand Down
41 changes: 7 additions & 34 deletions src/Controller/DefaultControler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace App\Controller;

use App\Form\Type\ContactType;
use App\Service\Mailer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -13,15 +14,18 @@ class DefaultControler extends AbstractController
{
/**
* @Route("/", name="index")
*
* @param Request $request
* @param Mailer $mailer
* @return Response
*/
public function index(Request $request, \Swift_Mailer $mailer): Response
public function index(Request $request, Mailer $mailer): Response
{
$form = $this->createForm(ContactType::class, null);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
if($this->sendEmail($data, $mailer)) {
if($mailer->sendEmail($form->getData())) {
$this->addFlash('contact', 'Votre email a été envoyé et sera traité dans les meilleurs délais.');
} else {
$this->addFlash('echec', 'Un problème a eu lieu durant l\'envoie, veuillez ré-essayer plus tard');
Expand All @@ -32,35 +36,4 @@ public function index(Request $request, \Swift_Mailer $mailer): Response
'form' => $form->createView(),
]);
}

/**
* @param $data
* @param \Swift_Mailer $mailer
*
* @return bool
* @todo New service for that
*/
private function sendEmail($data, \Swift_Mailer $mailer)
{
$mail = new \Swift_Message();
$mail
-> setSubject($data['objet'])
-> setFrom($data['email'])
-> setTo('[email protected]')
-> setBody(
$this -> renderView('emails/contact.html.twig', [
'data' => $data
]), 'text/html'
)
;

if($mailer -> send($mail))
{
return true;
}
else
{
return false;
}
}
}
10 changes: 5 additions & 5 deletions src/Form/Type/ContactType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class ContactType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class)
->add('email', TextType::class)
->add('subject', TextType::class)
->add('message', TextareaType::class)
->add('send', SubmitType::class)
->add('name', TextType::class, ['label' => 'Nom'])
->add('email', TextType::class, ['label' => 'E-mail'])
->add('subject', TextType::class, ['label' => 'Sujet'])
->add('message', TextareaType::class, ['label' => 'Message'])
->add('send', SubmitType::class, ['label' => 'Envoyer'])
;
}

Expand Down
39 changes: 21 additions & 18 deletions src/Service/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,44 @@

namespace App\Service;

use Twig\Environment;

class Mailer
{
public function __construct()
{
/** @var Environment */
private $twig;

/** @var \Swift_Mailer */
private $mailer;

public function __construct(Environment $twig, \Swift_Mailer $mailer)
{
$this->twig = $twig;
$this->mailer = $mailer;
}

/**
* @param $data
* @param \Swift_Mailer $mailer
*
* @param $data
* @return bool
* @todo New service for that
*/
private function sendEmail($data, \Swift_Mailer $mailer)
public function sendEmail($data)
{
$mail = new \Swift_Message();
$mail
-> setSubject($data['objet'])
-> setFrom($data['email'])
-> setTo('[email protected]')
-> setBody(
$this->renderView('emails/contact.html.twig', [
->setSubject($data['objet'])
->setFrom($data['email'])
->setTo('[email protected]')
->setBody(
$this->twig->render('emails/contact.html.twig', [
'data' => $data
]), 'text/html'
)
;

if($mailer -> send($mail))
{
return true;
}
else
{
if (0 === $this->mailer->send($mail)){
return false;
}

return true;
}
}
3 changes: 3 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@
"config/packages/test/swiftmailer.yaml"
]
},
"symfony/templating": {
"version": "v5.3.7"
},
"symfony/translation": {
"version": "5.3",
"recipe": {
Expand Down
3 changes: 2 additions & 1 deletion templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@
{% endblock %}

{% block contact_form %}
{% endblock %}
<div class="section contact-form">
<div class="row">
<div class="col s12 m6 l6 contact-text">Un renseignement ?
Expand Down Expand Up @@ -245,6 +244,8 @@
</div>
</div>
<!-- # Contact Me End # -->
{% endblock %}

<!-- Footer -->
<footer id="footer">
<div class="copyright">
Expand Down
13 changes: 12 additions & 1 deletion templates/cv.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,18 @@
{% endblock %}

{% block contact_form %}
{{ form(form) }}
<div class="section contact-form">
<div class="row">
<div class="col s12 m6 l6 contact-text">
Un renseignement ?
<br>
<br> Je suis à votre écoute.
</div>
<div class="col s12 m6 l6">
{{ form(form) }}
</div>
</div>
</div>
{% endblock %}


Expand Down
File renamed without changes.
33 changes: 33 additions & 0 deletions templates/form/theme/custom.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{# Rows #}
{% block form_row -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- endif -%}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('') ~ ' input-field' ~ ((not compound or force_error|default(false)) and not valid ? ' is-invalid'))|trim})} %}{{ block('attributes') }}{% endwith %}>
{{- form_widget(form, widget_attr) -}}
{{- form_help(form) -}}
{{- form_label(form) -}}
</div>
{%- endblock form_row %}

{% block submit_row -%}
{%- set widget_attr = {attr: {'class': 'btn dark-bg waves-effect'}} -%}
{{- form_widget(form, widget_attr) -}}
{%- endblock submit_row %}

{# Widgets #}

{% block textarea_widget -%}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' materialize-textarea')|trim}) %}
<textarea {{ block('widget_attributes') }}>{{ value }}</textarea>
{%- endblock textarea_widget %}

{#
div class input-field
textarea class materialize-textarea
input class validate
submit btn
<i class="btn dark-bg waves-effect waves-input-wrapper" style=""><input type="submit" class="waves-button-input" value="ENVOYER"></i>
#}
Binary file removed tmp/CV/BMA_CV_2016.pdf
Binary file not shown.
Binary file removed tmp/CV/BMA_CV_2017.pdf
Binary file not shown.
Binary file removed tmp/CV/BMA_CV_2018.pdf
Binary file not shown.
Binary file removed tmp/assets/.DS_Store
Binary file not shown.
Binary file removed tmp/assets/css/.DS_Store
Binary file not shown.
Loading

0 comments on commit 04a1d76

Please sign in to comment.