Skip to content

Commit

Permalink
EventSelectionContentType added; Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
manuxi committed Mar 28, 2021
1 parent d7ba660 commit e57e208
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 47 deletions.
8 changes: 0 additions & 8 deletions src/Admin/EventAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,18 @@
class EventAdmin extends Admin
{
public const LIST_VIEW = 'app.event.list';

public const ADD_FORM_VIEW = 'app.event.add_form';

public const ADD_FORM_DETAILS_VIEW = 'app.event.add_form.details';

public const EDIT_FORM_VIEW = 'app.event.edit_form';

public const EDIT_FORM_DETAILS_VIEW = 'app.event.edit_form.details';

public const SECURITY_CONTEXT = 'sulu.modules.events';

//seo,excerpt, etc
public const EDIT_FORM_VIEW_SEO = 'app.event.edit_form.seo';

public const EDIT_FORM_VIEW_EXCERPT = 'app.event.edit_form.excerpt';

private $viewBuilderFactory;

private $securityChecker;

private $webspaceManager;

public function __construct(
Expand Down
5 changes: 0 additions & 5 deletions src/Admin/LocationAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@
class LocationAdmin extends Admin
{
public const LIST_VIEW = 'app.location.list';

public const ADD_FORM_VIEW = 'app.location.add_form';

public const ADD_FORM_DETAILS_VIEW = 'app.location.add_form.details';

public const EDIT_FORM_VIEW = 'app.location.edit_form';

public const EDIT_FORM_DETAILS_VIEW = 'app.location.edit_form.details';

private $viewBuilderFactory;

private $securityChecker;

public function __construct(
Expand Down
50 changes: 50 additions & 0 deletions src/Content/EventSelectionContentType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Manuxi\SuluEventBundle\Content;

use Manuxi\SuluEventBundle\Entity\Event;
use Manuxi\SuluEventBundle\Repository\EventRepository;
use Sulu\Component\Content\Compat\PropertyInterface;
use Sulu\Component\Content\SimpleContentType;

class EventSelectionContentType extends SimpleContentType
{

private $eventRepository;

public function __construct(EventRepository $eventRepository)
{
parent::__construct('event_selection');

$this->eventRepository = $eventRepository;
}

/**
* @return Event[]
*/
public function getContentData(PropertyInterface $property): array
{
$ids = $property->getValue();
$locale = $property->getStructure()->getLanguageCode();

$events = [];
foreach ($ids ?: [] as $id) {
$event = $this->eventRepository->findById((int) $id, $locale);
if ($event && $event->isEnabled()) {
$events[] = $event;
}
}

return $events;
}

/**
* @return mixed[]
*/
public function getViewData(PropertyInterface $property): array
{
return $property->getValue();
}
}
23 changes: 0 additions & 23 deletions src/Repository/EventSeoRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
*/
class EventSeoRepository extends ServiceEntityRepository
{
// use DataProviderRepositoryTrait {
// findByFilters as parentFindByFilters;
// }

public function __construct(ManagerRegistry $registry)
{
Expand Down Expand Up @@ -75,24 +72,4 @@ public function findById(int $id, string $locale): ?EventSeo
return $eventSeo;
}

// /**
// * @param mixed[] $filters
// */
// public function findByFilters($filters, $page, $pageSize, $limit, $locale, $options = [])
// {
// $entities = $this->parentFindByFilters($filters, $page, $pageSize, $limit, $locale, $options);
//
// return array_map(
// function (EventSeo $entity) use ($locale) {
// return $entity->setLocale($locale);
// },
// $entities
// );
// }
//
// protected function appendJoins(QueryBuilder $queryBuilder, string $alias, string $locale): void
// {
// $queryBuilder->innerJoin($alias . '.translations', 'translation', Join::WITH, 'translation.locale = :locale');
// $queryBuilder->setParameter('locale', $locale);
// }
}
5 changes: 0 additions & 5 deletions src/Resources/config/routes.yml

This file was deleted.

19 changes: 13 additions & 6 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,26 @@
<tag name="sulu.content.type" alias="event_selection"/>
</service>

<service id="sulu_event.event_data_provider" class="Manuxi\SuluEventBundle\Content\EventDataProvider">
<service id="sulu_event.country_code_select" class="Manuxi\SuluEventBundle\Service\CountryCodeSelect" public="true"/>

<service id="Manuxi\SuluEventBundle\Routing\EventRouteDefaultsProvider">
<argument type="service" id="sulu_event.repository.event"/>
<argument type="service" id="sulu_core.array_serializer"/>

<tag name="sulu.smart_content.data_provider" alias="events"/>
<tag name="sulu_route.defaults_provider"/>
</service>

<service id="sulu_event.country_code_select" class="Manuxi\SuluEventBundle\Service\CountryCodeSelect" public="true"/>
<service id="Manuxi\SuluEventBundle\Content\EventSelectionContentType">
<argument type="service" id="sulu_event.repository.event"/>

<service id="Manuxi\SuluEventBundle\Routing\EventRouteDefaultsProvider">
<tag name="sulu.content.type" alias="event_selection"/>
</service>

<service id="sulu_event.event_data_provider" class="Manuxi\SuluEventBundle\Content\EventDataProvider">
<argument type="service" id="sulu_event.repository.event"/>
<argument type="service" id="sulu_core.array_serializer"/>

<tag name="sulu_route.defaults_provider"/>
<tag name="sulu.smart_content.data_provider" alias="events"/>
</service>

</services>
</container>

0 comments on commit e57e208

Please sign in to comment.