Skip to content

Commit 4f8f753

Browse files
committed
5110: Made event organizer required
1 parent 76cfaae commit 4f8f753

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ See [keep a changelog] for information about writing changes to this log.
88

99
## [Unreleased]
1010

11-
- Updated fixtures
11+
- Updated fixtures. Made event organizer required.
1212

1313
## [1.1.6] - 2025-03-27
1414

src/Controller/Admin/EventCrudController.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
1313
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
1414
use EasyCorp\Bundle\EasyAdminBundle\Config\Asset;
15-
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
1615
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
1716
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
1817
use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
@@ -134,20 +133,22 @@ public function configureFields(string $pageName): iterable
134133
yield FormField::addFieldset('Organizer information')
135134
->setLabel(new TranslatableMessage('admin.event.organizer.headline'));
136135

137-
if ($this->isGranted(UserRoles::ROLE_EDITOR->value)) {
138-
yield AssociationField::new('organization')
139-
->setLabel(new TranslatableMessage('admin.event.edited.organization'));
140-
} else {
141-
yield AssociationField::new('organization')
142-
->setLabel(new TranslatableMessage('admin.event.edited.organization'))
143-
->setQueryBuilder(
144-
fn (QueryBuilder $queryBuilder) => $queryBuilder
145-
->select('o')
146-
->from(Organization::class, 'o')
147-
->where(':user MEMBER OF o.users')
148-
->setParameter('user', $this->getUser())
149-
);
136+
$organization = AssociationField::new('organization')
137+
->setLabel(new TranslatableMessage('admin.event.edited.organization'))
138+
// We assume at least one organization exist for non-editor users
139+
// (cf. editor stuff below).
140+
->setRequired(true)
141+
->setFormTypeOption('placeholder', new TranslatableMessage('admin.event.organizer.placeholder'));
142+
// Limit organization choices for non-editors to the organizations the user is a member of.
143+
if (!$this->isGranted(UserRoles::ROLE_EDITOR->value)) {
144+
$userOrganizations = $this->getUser()->getOrganizations();
145+
$organization
146+
->setFormTypeOption('choices', $userOrganizations)
147+
// Make sure that the user is not forced to make a choice if none exists.
148+
->setRequired($userOrganizations->count() > 0);
150149
}
150+
yield $organization;
151+
151152
yield AssociationField::new('partners')
152153
->setLabel(new TranslatableMessage('admin.event.edited.partners'))
153154
->hideOnDetail();

translations/messages+intl-icu.da.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,10 @@
653653
<source>admin.user.registrationNotes</source>
654654
<target state="translated">Ønskede arrangører</target>
655655
</trans-unit>
656+
<trans-unit id="MaqqeAe" resname="admin.event.organizer.placeholder">
657+
<source>admin.event.organizer.placeholder</source>
658+
<target state="translated">Vælg arrangør</target>
659+
</trans-unit>
656660
</body>
657661
</file>
658662
</xliff>

translations/messages+intl-icu.en.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,10 @@
653653
<source>admin.user.registrationNotes</source>
654654
<target>Requested organizers</target>
655655
</trans-unit>
656+
<trans-unit id="MaqqeAe" resname="admin.event.organizer.placeholder">
657+
<source>admin.event.organizer.placeholder</source>
658+
<target>admin.event.organizer.placeholder</target>
659+
</trans-unit>
656660
</body>
657661
</file>
658662
</xliff>

0 commit comments

Comments
 (0)