Skip to content

Commit

Permalink
Update requirements to PHP 7.4 and add variable type specifications i…
Browse files Browse the repository at this point in the history
…n classes

Add admin area base (#22)
Add translations for admin area
Add __toString() for user and character entity
Fix getUsername in user entity to resolve to the name (not mail)
  • Loading branch information
Onyxmoon committed Aug 6, 2020
1 parent 0487414 commit 41e7084
Show file tree
Hide file tree
Showing 15 changed files with 445 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .idea/php.xml

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

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.2.5",
"php": "^7.4",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
Expand Down
2 changes: 1 addition & 1 deletion config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ security:
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
# - { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
Binary file added public/media/5f2412b90f26c_Kolkja.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/Action/CreateUserObjectAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

final class CreateUserObjectAction extends AbstractController
{
private $confirmationEmailController;
private $validator;
private ConfirmationEmailController $confirmationEmailController;
private ValidatorInterface $validator;

public function __construct(ConfirmationEmailController $confirmationEmailController, ValidatorInterface $validator)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Action/PatchUserCredentialsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

final class PatchUserCredentialsAction extends AbstractController
{
private $passwordEncoder;
private $authorizationChecker;
private $confirmationEmailController;
private UserPasswordEncoderInterface $passwordEncoder;
private AuthorizationCheckerInterface $authorizationChecker;
private ConfirmationEmailController $confirmationEmailController;

public function __construct(UserPasswordEncoderInterface $passwordEncoder, AuthorizationCheckerInterface $authorizationChecker, ConfirmationEmailController $confirmationEmailController)
{
Expand Down
25 changes: 20 additions & 5 deletions src/Controller/Administration/AdminDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@

namespace App\Controller\Administration;

use App\Entity\Character;
use App\Entity\User;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;

use Symfony\Contracts\Translation\TranslatorInterface;


class AdminDashboardController extends AbstractDashboardController
{
private TranslatorInterface $translator;

public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}

/**
* @Route("/admin", name="admin")
*/
Expand All @@ -24,17 +33,23 @@ public function index(): Response

public function configureDashboard(): Dashboard
{
$this->translator->setLocale($this->getUser()->getLocale());
$package = new Package(new EmptyVersionStrategy());
return Dashboard::new()
->setTitle('<div style="display: flex"><object data="'
. $package->getUrl("assets/images/OptolithCloud-Combined-SafeSpace.svg")
. '" type="image/svg+xml" width="auto" height="auto"></object>'
. '<p style="align-self: center; margin-top: 1rem">&vert;&nbsp;&nbsp;Administration</p></div>');
. '" type="image/svg+xml"></object>'
. '<span style="align-self: center;">&vert;&nbsp;Administration</span></div>')
->setTranslationDomain("administration")
;
}

public function configureMenuItems(): iterable
{
yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home');
// yield MenuItem::linkToCrud('The Label', 'icon class', EntityClass::class);
yield MenuItem::linktoDashboard("menu.label.item.dashboard", 'fa fa-circle');
yield MenuItem::section("menu.label.section.cloudData", 'fa fa-cloud');
yield MenuItem::linkToCrud("menu.label.item.users", "fa fa-user", User::class);
yield MenuItem::linkToCrud("menu.label.item.characters", "fa fa-mask", Character::class);
yield MenuItem::section("menu.label.section.system", 'fa fa-info-circle');
}
}
47 changes: 47 additions & 0 deletions src/Controller/Administration/CharacterCrudController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Controller\Administration;

use App\Entity\Character;
use App\Entity\User;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Router\CrudUrlGenerator;

class CharacterCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Character::class;
}

public function configureCrud(Crud $crud): Crud
{
return $crud
->setEntityLabelInSingular('entity.character.header.singular')
->setEntityLabelInPlural("entity.character.header.plural")
;
}

public function configureFields(string $pageName): iterable
{
yield IdField::new('id')->setLabel('entity.character.label.id')->hideOnForm()->hideOnIndex();
yield TextField::new('displayName')->setLabel('entity.character.label.displayName');
yield AssociationField::new('owner')->setLabel('entity.character.label.owner')->autocomplete();
}

public function configureActions(Actions $actions): Actions
{
return $actions
->add(Crud::PAGE_INDEX, Action::DETAIL);
}
}
119 changes: 119 additions & 0 deletions src/Controller/Administration/UserCrudController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

namespace App\Controller\Administration;

use App\Entity\Character;
use App\Entity\MediaObject;
use App\Entity\User;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
use EasyCorp\Bundle\EasyAdminBundle\Field\LanguageField;
use EasyCorp\Bundle\EasyAdminBundle\Field\LocaleField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TimeField;
use EasyCorp\Bundle\EasyAdminBundle\Router\CrudUrlGenerator;
use Symfony\Contracts\Translation\TranslatorInterface;
use Vich\UploaderBundle\Form\Type\VichImageType;

class UserCrudController extends AbstractCrudController
{
private TranslatorInterface $translator;

public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}

public static function getEntityFqcn(): string
{
return User::class;
}

public function configureCrud(Crud $crud): Crud
{
return $crud
->setEntityLabelInSingular('entity.user.header.singular')
->setEntityLabelInPlural("entity.user.header.plural")
;
}

public function configureFields(string $pageName): iterable
{
yield IdField::new('id')->setLabel('entity.user.label.id')->hideOnForm()->hideOnIndex();
yield TextField::new('displayName')->setLabel('entity.user.label.displayName');
yield EmailField::new('email')->setLabel('entity.user.label.email');
yield ChoiceField::new('locale')->setLabel('entity.user.label.locale')->setChoices(['de-DE' => 'de-DE', 'en-US' => 'en-US', 'nl-BE' => 'nl-BE', 'fr-FR' => 'fr-FR', 'es-ES' => 'es-ES']);
yield BooleanField::new('isActive')->setLabel('entity.user.label.isActive');
yield BooleanField::new('confirmedEmail')->setLabel('entity.user.label.confirmedEmail');
yield TextField::new('plainPassword')->setLabel('entity.user.label.newPassword')->hideOnDetail()->hideOnIndex();
yield ChoiceField::new('roles')->setLabel('entity.user.label.roles')->setChoices(['User' => 'ROLE_USER', 'Administrator' => 'ROLE_ADMIN'])->allowMultipleChoices()->hideOnIndex();
yield DateTimeField::new('registrationDate')->setLabel('entity.user.label.registrationDate')->hideOnIndex();
yield AssociationField::new('characters')->setLabel('entity.user.label.characters')->autocomplete();
yield AssociationField::new('mediaObjects')->setLabel('entity.user.label.mediaObjects')->hideOnForm();
}

public function configureActions(Actions $actions): Actions
{
$showCharactersIndex = Action::new('showCharactersIndex', false, 'fa fa-mask')
->linkToUrl(function (User $user) {
$crudUrlGenerator = $this->get(CrudUrlGenerator::class);
return $crudUrlGenerator->build()->setController(CharacterCrudController::class)->setAction(Crud::PAGE_INDEX)->set('query',$user->getId());
})
->setHtmlAttributes(['title' => $this->translator->trans('entity.user.label.showCharacters', [], 'administration', $this->getUser()->getLocale())])
;

$showCharactersDetail = Action::new('showCharactersDetail', 'entity.user.label.showCharacters', 'fa fa-mask')
->linkToUrl(function (User $user) {
$crudUrlGenerator = $this->get(CrudUrlGenerator::class);
return $crudUrlGenerator->build()->setController(CharacterCrudController::class)->setAction(Crud::PAGE_INDEX)->set('query',$user->getId());
})
->setHtmlAttributes(['title' => $this->translator->trans('entity.user.label.showCharacters', [], 'administration', $this->getUser()->getLocale())])
;

$showMediaIndex = Action::new('showMediaIndex', false, 'fa fa-images')
->linkToUrl(function (User $user) {
$crudUrlGenerator = $this->get(CrudUrlGenerator::class);
return $crudUrlGenerator->build()->setController(CharacterCrudController::class)->setAction(Crud::PAGE_INDEX)->set('query',$user->getId());
})
->setHtmlAttributes(['title' => $this->translator->trans('entity.user.label.showCharacters', [], 'administration', $this->getUser()->getLocale())])
;

$showMediaDetail = Action::new('showMediaDetail', 'entity.user.label.showMedia', 'fa fa-images')
->linkToUrl(function (User $user) {
$crudUrlGenerator = $this->get(CrudUrlGenerator::class);
return $crudUrlGenerator->build()->setController(CharacterCrudController::class)->setAction(Crud::PAGE_INDEX)->set('query',$user->getId());
})
->setHtmlAttributes(['title' => $this->translator->trans('entity.user.label.showCharacters', [], 'administration', $this->getUser()->getLocale())])
;


return $actions
->add(Crud::PAGE_INDEX, Action::DETAIL)
->add(Crud::PAGE_INDEX, $showMediaIndex)
->add(Crud::PAGE_DETAIL, $showMediaDetail)
->add(Crud::PAGE_INDEX, $showCharactersIndex)
->add(Crud::PAGE_DETAIL, $showCharactersDetail)
->update(Crud::PAGE_INDEX, Action::DETAIL, function (Action $action) {
return $action->setIcon('fa fa-eye')->setLabel(false)->setHtmlAttributes(['title' => $this->translator->trans('action.detail', [], 'EasyAdminBundle', $this->getUser()->getLocale())]);
})
->update(Crud::PAGE_INDEX, Action::EDIT, function (Action $action) {
return $action->setIcon('fa fa-edit')->setLabel(false)->setHtmlAttributes(['title' => $this->translator->trans('action.edit', [], 'EasyAdminBundle', $this->getUser()->getLocale())]);
})
->update(Crud::PAGE_INDEX, Action::DELETE, function (Action $action) {
return $action->setIcon('fa fa-user-times')->setLabel(false)->setHtmlAttributes(['title' => $this->translator->trans('action.delete', [], 'EasyAdminBundle', $this->getUser()->getLocale())]);
});
}

}
5 changes: 4 additions & 1 deletion src/Entity/Character.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,8 @@ public function setAvatar(?MediaObject $avatar): self
return $this;
}


public function __toString()
{
return $this->id . " (" . $this->displayName . ")";
}
}
8 changes: 7 additions & 1 deletion src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Serializer\Annotation\SerializedName;
use App\Action\PatchUserCredentialsAction;
use App\Action\CreateUserObjectAction;
use Vich\UploaderBundle\Templating\Helper\UploaderHelper;

/**
* @UniqueEntity(fields={"email"})
Expand Down Expand Up @@ -233,7 +234,7 @@ public function setEmail(string $email): self
*/
public function getUsername(): string
{
return (string) $this->email;
return (string) $this->displayName;
}

/**
Expand Down Expand Up @@ -492,4 +493,9 @@ public function setLocale(string $locale): self
return $this;
}

public function __toString()
{
return (string)$this->displayName;
}

}
14 changes: 14 additions & 0 deletions translations/EasyAdminBundle+intl-icu.de-DE.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en-US" target-language="de-DE" datatype="plaintext" original="file.ext">
<header>
<tool tool-id="symfony" tool-name="Symfony"/>
</header>
<body>
<trans-unit id="rSWmi1r" resname="label.form.empty_value">
<source>label.form.empty_value</source>
<target>__label.form.empty_value</target>
</trans-unit>
</body>
</file>
</xliff>
14 changes: 14 additions & 0 deletions translations/EasyAdminBundle+intl-icu.en-US.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en-US" target-language="en-US" datatype="plaintext" original="file.ext">
<header>
<tool tool-id="symfony" tool-name="Symfony"/>
</header>
<body>
<trans-unit id="rSWmi1r" resname="label.form.empty_value">
<source>label.form.empty_value</source>
<target>__label.form.empty_value</target>
</trans-unit>
</body>
</file>
</xliff>
Loading

0 comments on commit 41e7084

Please sign in to comment.