Skip to content

Commit

Permalink
Merge pull request #5 from maximehuran/feature/customize-contact-page
Browse files Browse the repository at this point in the history
Be able to customize contact request page
  • Loading branch information
maximehuran authored Aug 27, 2024
2 parents 0a28334 + 124365a commit 9643d20
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 4 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
[![Recipe Status](https://img.shields.io/github/actions/workflow/status/monsieurbiz/SyliusContactRequestPlugin/recipe.yaml?branch=master&label=recipes&logo=github)](https://github.com/monsieurbiz/SyliusContactRequestPlugin/actions?query=workflow%3ASecurity)
[![Security Status](https://img.shields.io/github/actions/workflow/status/monsieurbiz/SyliusContactRequestPlugin/security.yaml?branch=master&label=security&logo=github)](https://github.com/monsieurbiz/SyliusContactRequestPlugin/actions?query=workflow%3ASecurity)

This plugin saves contact requests made on the native form into the database allowing us to see them in the back-office of Sylius.
This plugin allows you to customize the contact page on the front-end of your Sylius store. It stores all contact requests made through the native Sylius form in the database, making them accessible directly from the Sylius back office.

![Demo of the Contact Request](docs/images/demo1.png)
![Demo of the Contact Request](docs/images/demo2.png)
![Demo of the Contact Request](docs/images/admin-list.png)
![Demo of the Contact Request](docs/images/demo-shop.jpg)

## Compatibility

Expand All @@ -34,6 +34,12 @@ composer require monsieurbiz/sylius-contact-request-plugin

## Getting started

### Contact page customization

![Demo of the Contact Request](docs/images/settings.jpg)

### Contact request storage

Submit a contact request from the native contact form. Them go in the back-office in the customer menu node you will have a new menu 'contact requests', click on it and
you can see a grid with the contact requests created.
Obviously, this plugin is not retroactive and contact requests made before the plugin was installed will not be displayed.
Expand Down Expand Up @@ -65,6 +71,23 @@ imports:
resource: '@MonsieurBizSyliusContactRequestPlugin/Resources/config/routes.yaml'
```

To override the default sylius route for contact page, create a new file `config/routes/sylius_shop_contact_request_override.yaml` and add the following configuration:

```yaml
sylius_shop_contact_request:
path: /{_locale}/contact
requirements:
_locale: ^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$
methods: [GET, POST]
defaults:
_controller: sylius.controller.shop.contact::requestAction
_sylius:
redirect: sylius_shop_homepage
template: '@MonsieurBizSyliusContactRequestPlugin/Shop/ContactRequest/request.html.twig'
```

This is the same as Sylius route configuration instead of the template key which is overridden to use the plugin template.

## Contributing

You can find a way to run the plugin without effort in the file [DEVELOPMENT.md](./DEVELOPMENT.md).
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"license": "MIT",
"require": {
"php": "^8.0",
"sylius/sylius": ">=1.11 <1.14"
"sylius/sylius": ">=1.11 <1.14",
"monsieurbiz/sylius-settings-plugin": "^1.2.0",
"monsieurbiz/sylius-rich-editor-plugin": "^2.8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.16",
Expand Down
File renamed without changes
Binary file added docs/images/demo-shop.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/demo2.png
Binary file not shown.
Binary file added docs/images/settings.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions src/Form/Type/ContactSettingsType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/*
* This file is part of Monsieur Biz' Contact Request plugin for Sylius.
*
* (c) Monsieur Biz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusContactRequestPlugin\Form\Type;

use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\RichEditorType;
use MonsieurBiz\SyliusSettingsPlugin\Form\AbstractSettingsType;
use MonsieurBiz\SyliusSettingsPlugin\Form\SettingsTypeInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

final class ContactSettingsType extends AbstractSettingsType implements SettingsTypeInterface
{
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$this->addWithDefaultCheckbox(
$builder,
'content_before_form',
RichEditorType::class,
[
'label' => 'monsieurbiz.contact_request.ui.content_before_form',
'required' => false,
]
);
$this->addWithDefaultCheckbox(
$builder,
'content_after_form',
RichEditorType::class,
[
'label' => 'monsieurbiz.contact_request.ui.content_after_form',
'required' => false,
]
);
$this->addWithDefaultCheckbox(
$builder,
'meta_title',
TextType::class,
[
'label' => 'monsieurbiz.contact_request.ui.meta_title',
'required' => false,
]
);
$this->addWithDefaultCheckbox(
$builder,
'meta_description',
TextType::class,
[
'label' => 'monsieurbiz.contact_request.ui.meta_description',
'required' => false,
]
);
$this->addWithDefaultCheckbox(
$builder,
'meta_keywords',
TextType::class,
[
'label' => 'monsieurbiz.contact_request.ui.meta_keywords',
'required' => false,
]
);
$this->addWithDefaultCheckbox(
$builder,
'hide_sylius_default_content',
CheckboxType::class,
[
'label' => 'monsieurbiz.contact_request.ui.hide_sylius_default_content',
'required' => false,
]
);
}
}
1 change: 1 addition & 0 deletions src/Resources/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
imports:
- { resource: 'resources.yaml' }
- { resource: 'grids/*' }
- { resource: 'monsieurbiz/*.yaml' }
10 changes: 10 additions & 0 deletions src/Resources/config/monsieurbiz/settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
monsieurbiz_sylius_settings:
plugins:
monsieurbiz_contact_request.contact:
vendor_name: Monsieur Biz
plugin_name: monsieurbiz.contact_request.settings.plugin_name
description: monsieurbiz.contact_request.settings.description
icon: phone
use_locales: true
classes:
form: MonsieurBiz\SyliusContactRequestPlugin\Form\Type\ContactSettingsType
9 changes: 9 additions & 0 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ monsieurbiz:
contact_request: 'Contact request'
email: 'Email'
message: 'Message'
content_before_form: 'Content before the contact form'
content_after_form: 'Content after the contact form'
meta_title: "Meta Title"
meta_description: "Meta Description"
meta_keywords: "Meta Keyword"
hide_sylius_default_content: "Hide Sylius default content"
settings:
plugin_name: 'Contact page'
description: 'Configure the contact page'
9 changes: 9 additions & 0 deletions src/Resources/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ monsieurbiz:
contact_request: 'Demande de contact'
email: 'Email'
message: 'Message'
content_before_form: 'Contenu avant le formulaire de contact'
content_after_form: 'Contenu après le formulaire de contact'
meta_title: "Meta Title"
meta_description: "Meta Description"
meta_keywords: "Meta Keyword"
hide_sylius_default_content: "Masquer le contenu par défaut de Sylius"
settings:
plugin_name: 'Page de contact'
description: 'Configurer la page de contact'
Empty file removed src/Resources/views/.gitkeep
Empty file.
65 changes: 65 additions & 0 deletions src/Resources/views/Shop/ContactRequest/request.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{% extends '@SyliusShop/layout.html.twig' %}

{% form_theme form '@SyliusShop/Form/theme.html.twig' %}

{% set metaTitle = setting('monsieurbiz_contact_request.contact', 'meta_title')|default('') %}
{% set metaDescription = setting('monsieurbiz_contact_request.contact', 'meta_description')|default('') %}
{% set metaKeywords = setting('monsieurbiz_contact_request.contact', 'meta_keywords')|default('') %}

{% block title %}{{ metaTitle is not empty ? metaTitle : (('sylius.ui.contact_us'|trans) ~ ' | ' ~ parent()) }}{% endblock %}

{% block metatags %}
{{ parent() }}
<meta property="og:type" content="page" />
{% if metaTitle is not empty %}
<meta property="og:title" content="{{ metaTitle }}"/>
{% endif %}
{% if metaDescription is not empty %}
<meta name="description" property="og:description" content="{{ metaDescription }}"/>
{% endif %}
{% if metaKeywords is not empty %}
<meta name="keywords" content="{{ metaKeywords }}"/>
{% endif %}
{% endblock %}

{% block content %}
<div class="ui hidden divider"></div>
<div class="ui two column centered stackable grid">
<div class="column">
{% set hideSyliusDefaultContent = setting('monsieurbiz_contact_request.contact', 'hide_sylius_default_content')|default(false) %}
{% if not hideSyliusDefaultContent %}
<h1 class="ui header">
<i class="circular mail icon"></i>
<div class="content">
{{ 'sylius.ui.contact_us'|trans }}
<div class="sub header">{{ 'sylius.ui.use_the_contact_form_below_to_send_us_a_message'|trans }}</div>

{{ sylius_template_event('sylius.shop.contact.request.after_content_header') }}
</div>
</h1>
{% endif %}

{% set contentBeforeForm = setting('monsieurbiz_contact_request.contact', 'content_before_form')|default('') %}
{% if contentBeforeForm is not empty %}
{{ contentBeforeForm|monsieurbiz_richeditor_render_field }}
{% endif %}

<div class="ui segment">
{{ form_start(form, {'action': path('sylius_shop_contact_request'), 'attr': {'class': 'ui large loadable form', 'novalidate': 'novalidate'}}) }}
{{ form_row(form.email, sylius_test_form_attribute('contact-email')) }}
{{ form_row(form.message, sylius_test_form_attribute('contact-message')) }}

{{ sylius_template_event('sylius.shop.contact.request.form', {'form': form}) }}

{{ form_row(form._token) }}
<button type="submit" class="ui fluid large primary submit button" {{ sylius_test_html_attribute('send-button') }}>{{ 'sylius.ui.send'|trans }}</button>
{{ form_end(form, {'render_rest': false}) }}
</div>

{% set contentAfterForm = setting('monsieurbiz_contact_request.contact', 'content_after_form')|default('') %}
{% if contentAfterForm is not empty %}
{{ contentAfterForm|monsieurbiz_richeditor_render_field }}
{% endif %}
</div>
</div>
{% endblock %}

0 comments on commit 9643d20

Please sign in to comment.