Skip to content

Commit

Permalink
Add category management
Browse files Browse the repository at this point in the history
  • Loading branch information
Dumazeau committed Jul 19, 2024
1 parent 9856a13 commit af86ce3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/Domain/Email/AbstractEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ abstract class AbstractEmail
protected const BODY_TYPE_TRANSLATION = 'translation';
protected const BODY_TYPE_TWIG = 'twig';

protected const CATEGORY = null;

protected const TRANSLATION_DOMAIN = 'emails';
protected const TEMPLATING_FOLDER = 'emails';

Expand Down Expand Up @@ -72,6 +74,24 @@ public function getName(): string
);
}

public function getCategorySlug(): ?string
{
return static::CATEGORY;
}

public function getCategoryName(): ?string
{
if (static::CATEGORY === null) {
return null;
}

return $this->translator->trans(
\sprintf('category.%s', static::CATEGORY),
[],
static::TRANSLATION_DOMAIN
);
}

public function canSeeEmailInAdministration(): bool
{
return true;
Expand Down
10 changes: 10 additions & 0 deletions src/Domain/Email/EmailCategoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace RichId\EmailTemplateBundle\Domain\Email;

interface EmailCategoryInterface
{
public function getSlug(): string;
}
4 changes: 3 additions & 1 deletion src/Domain/Fetcher/AdministrationEmailsFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public function __invoke(): array
$email->getEmailSlug(),
$email->getName(),
($this->emailTemplateFetcher)($email->getEmailSlug()),
$email::TEMPLATES
$email::TEMPLATES,
$email->getCategorySlug(),
$email->getCategoryName()
);

continue;
Expand Down
9 changes: 8 additions & 1 deletion src/Domain/Model/AdministrationEmailModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@ final class AdministrationEmailModel
/** @var string[] */
public array $allowedValues;

public ?string $categorySlug = null;
public ?string $categoryName = null;

/** @param string[] $allowedValues */
public static function build(
string $slug,
string $name,
string $value,
array $allowedValues
array $allowedValues,
?string $categorySlug = null,
?string $categoryName = null
): self {
$model = new self();

$model->slug = $slug;
$model->name = $name;
$model->value = $value;
$model->allowedValues = $allowedValues;
$model->categorySlug = $categorySlug;
$model->categoryName = $categoryName;

return $model;
}
Expand Down

0 comments on commit af86ce3

Please sign in to comment.