-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #514 from BitBagCommerce/feature/OP-461
OP-461: Page templates
- Loading branch information
Showing
76 changed files
with
1,721 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
@managing_templates | ||
Feature: Adding cms templates | ||
In order to create templates | ||
As an Administrator | ||
I want to be able to add new templates | ||
|
||
Background: | ||
Given the store operates on a single channel in "United States" | ||
And I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Creating template | ||
When I go to the create template page | ||
And I fill the name with "Test template" | ||
And I choose "Page" in Type field | ||
And I add it | ||
Then I should be notified that the template has been created | ||
|
||
@ui @javascript | ||
Scenario: Creating template with content elements | ||
When I go to the create template page | ||
And I fill the name with "Test template" | ||
And I choose "Page" in Type field | ||
And I click on Add button in Content elements section | ||
And I select "Textarea" content element | ||
And I click on Add button in Content elements section | ||
And I select "Single media" content element | ||
And I add it | ||
Then I should be notified that the template has been created | ||
And I should see newly created "Textarea" content element in Content elements section | ||
And I should see newly created "Single media" content element in Content elements section | ||
|
||
@ui | ||
Scenario: Trying to add template with existing name | ||
Given there is a template in the store with "New template" name | ||
When I go to the create template page | ||
And I fill the name with "New template" | ||
And I try to add it | ||
Then I should be notified that there is already existing template with provided name | ||
|
||
@ui | ||
Scenario: Adding new template with blank data | ||
When I go to the create template page | ||
And I add it | ||
And I should be notified that "Name" field cannot be blank | ||
|
||
@ui | ||
Scenario: Trying to add a template with too short data | ||
When I go to the create template page | ||
And I fill the name with "X" | ||
And I try to add it | ||
Then I should be notified that "Name" field is too short | ||
|
||
@ui | ||
Scenario: Trying to add a template with too long data | ||
When I go to the create template page | ||
And I fill "Name" field with 251 characters | ||
And I try to add it | ||
Then I should be notified that "Name" field is too long |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@managing_templates | ||
Feature: Managing cms templates | ||
In order to manage existing templates | ||
As an Administrator | ||
I want to be able to edit and remove existing templates | ||
|
||
Background: | ||
Given the store operates on a single channel in "United States" | ||
And I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Deleting template | ||
Given there is a template in the store with "Test template" name | ||
When I go to the templates page | ||
And I delete this template | ||
Then I should be notified that the template has been deleted | ||
And I should see empty list of templates | ||
|
||
@ui | ||
Scenario: Updating template | ||
Given there is a template in the store with "Test template" name | ||
When I go to the update "Test template" template page | ||
And I fill the name with "New template" | ||
And I update it | ||
Then I should be notified that the template has been successfully updated | ||
|
||
@ui @javascript | ||
Scenario: Updating template with content elements | ||
Given there is a template in the store with "Test template" name | ||
And there are "Textarea" and "Single media" content elements in this template | ||
When I go to the update "Test template" template page | ||
And I delete "Textarea" content element | ||
And I update it | ||
Then I should be notified that the template has been successfully updated | ||
And I should see only "Single media" content element in Content elements section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusCmsPlugin\Controller; | ||
|
||
use BitBag\SyliusCmsPlugin\Entity\TemplateInterface; | ||
use Sylius\Bundle\ResourceBundle\Controller\ResourceController; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
final class TemplateController extends ResourceController | ||
{ | ||
public function getContentElementsAction(int $id): JsonResponse | ||
{ | ||
$template = $this->getDoctrine()->getRepository(TemplateInterface::class)->find($id); | ||
if (null === $template) { | ||
return new JsonResponse([ | ||
'status' => 'error', | ||
'message' => 'Template not found', | ||
]); | ||
} | ||
|
||
return new JsonResponse([ | ||
'status' => 'success', | ||
'content' => $template->getContentElements(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusCmsPlugin\Entity; | ||
|
||
class Template implements TemplateInterface | ||
{ | ||
protected ?int $id; | ||
|
||
protected ?string $name; | ||
|
||
protected ?string $type; | ||
|
||
protected array $contentElements = []; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(?string $name): void | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function getType(): ?string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function setType(?string $type): void | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
public function getContentElements(): array | ||
{ | ||
return $this->contentElements; | ||
} | ||
|
||
public function setContentElements(array $contentElements): void | ||
{ | ||
$this->contentElements = $contentElements; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusCmsPlugin\Entity; | ||
|
||
use Sylius\Component\Resource\Model\ResourceInterface; | ||
|
||
interface TemplateInterface extends ResourceInterface | ||
{ | ||
public function getName(): ?string; | ||
|
||
public function setName(?string $name): void; | ||
|
||
public function getType(): ?string; | ||
|
||
public function setType(?string $type): void; | ||
|
||
public function getContentElements(): array; | ||
|
||
public function setContentElements(array $contentElements): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusCmsPlugin\Form\Type; | ||
|
||
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
abstract class AbstractTemplateAutocompleteChoiceType extends AbstractType | ||
{ | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefaults([ | ||
'resource' => 'bitbag_sylius_cms_plugin.template', | ||
'choice_name' => 'name', | ||
'choice_value' => 'id', | ||
]); | ||
} | ||
|
||
public function buildView( | ||
FormView $view, | ||
FormInterface $form, | ||
array $options, | ||
): void { | ||
$view->vars['remote_criteria_type'] = 'contains'; | ||
$view->vars['remote_criteria_name'] = 'phrase'; | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return ResourceAutocompleteChoiceType::class; | ||
} | ||
} |
Oops, something went wrong.