Skip to content

Commit

Permalink
Merge pull request #33 from matks/split-module-1
Browse files Browse the repository at this point in the history
Copy demoextendsymfonyform1 into demoextendsymfonyform3
  • Loading branch information
matks authored Jan 21, 2021
2 parents 293d6d4 + 22d695a commit 8fd3d4f
Show file tree
Hide file tree
Showing 20 changed files with 1,107 additions and 0 deletions.
4 changes: 4 additions & 0 deletions demoextendsymfonyform3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor/
composer.lock
.idea
js/node_modules
37 changes: 37 additions & 0 deletions demoextendsymfonyform3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Demonstration of how to use CQRS in a module

## About

This module adds a new field to Customer: a yes/no field "is allowed to review".
This new field appears:
- in the Customers listing as a new column
- in the Customers Add/Edit form as a new field you can manage

This modules demonstrates
- how to add this field, manage its content and its
properties using modern hooks in Symfony pages
- how to use custom [CQRS](https://devdocs.prestashop.com/1.7/development/architecture/domain/cqrs/) Commands and Queries to separate your domain from your application
- how to use Translator inside modern Symfony module

*This part is demonstrated as a possibility for your module, this is
not mandatory to be done this way.

### Supported PrestaShop versions

This module is compatible with and 1.7.6.0 and above versions.

### Requirements

1. Composer, see [Composer](https://getcomposer.org/) to learn more

### How to install

1. Download or clone module into `modules` directory of your PrestaShop installation
2. Rename the directory to make sure that module directory is named `demoextendsymfonyform3`*
3. `cd` into module's directory and run following commands:
- `composer install` - to download dependencies into vendor folder
4. Install module from Back Office

*Because the name of the directory and the name of the main module file must match.


11 changes: 11 additions & 0 deletions demoextendsymfonyform3/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "prestashop/demoextendsymfonyform3",
"description": "Help developers to understand how to create module using new hooks and apply best practices when using CQRS",
"autoload": {
"psr-4": {
"DemoCQRSHooksUsage\\": "src/"
}
},
"license": "MIT",
"type": "prestashop-module"
}
8 changes: 8 additions & 0 deletions demoextendsymfonyform3/config/routes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @see https://devdocs.prestashop.com/1.7/modules/concepts/controllers/admin-controllers/#how-to-map-an-action-of-your-controller-to-a-uri
ps_democqrshooksusage_toggle_is_allowed_for_review:
path: demo-cqrs-hook-usage/{customerId}/toggle-is-allowed-for-review
methods: [POST]
defaults:
_controller: 'DemoCQRSHooksUsage\Controller\Admin\CustomerReviewController::toggleIsAllowedForReviewAction'
requirements:
customerId: \d+
33 changes: 33 additions & 0 deletions demoextendsymfonyform3/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:
_defaults:
public: true
# @see https://devdocs.prestashop.com/1.7/development/architecture/migration-guide/forms/cqrs-usage-in-forms/ for CQRS pattern usage examples.
democqrshooksusage.domain.reviewer.command_handler.toggle_is_allowed_to_review_handler:
class: 'DemoCQRSHooksUsage\Domain\Reviewer\CommandHandler\ToggleIsAllowedToReviewHandler'
arguments:
- '@democqrshooksusage.repository.reviewer'
tags:
- name: tactician.handler
command: 'DemoCQRSHooksUsage\Domain\Reviewer\Command\ToggleIsAllowedToReviewCommand'

democqrshooksusage.domain.reviewer.query_handler.get_reviewer_settings_for_form_handler:
class: 'DemoCQRSHooksUsage\Domain\Reviewer\QueryHandler\GetReviewerSettingsForFormHandler'
arguments:
- '@democqrshooksusage.repository.reviewer'
tags:
- name: tactician.handler
command: 'DemoCQRSHooksUsage\Domain\Reviewer\Query\GetReviewerSettingsForForm'

democqrshooksusage.domain.reviewer.command_handler.update_is_allowed_to_review_handler:
class: 'DemoCQRSHooksUsage\Domain\Reviewer\CommandHandler\UpdateIsAllowedToReviewHandler'
arguments:
- '@democqrshooksusage.repository.reviewer'
tags:
- name: tactician.handler
command: 'DemoCQRSHooksUsage\Domain\Reviewer\Command\UpdateIsAllowedToReviewCommand'

democqrshooksusage.repository.reviewer:
class: 'DemoCQRSHooksUsage\Repository\ReviewerRepository'
arguments:
- '@doctrine.dbal.default_connection'
- '%database_prefix%'
Loading

0 comments on commit 8fd3d4f

Please sign in to comment.