Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Update Bundle #46

Open
wants to merge 21 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Api/Factory/NewsApiDtoFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

Check failure on line 1 in Api/Factory/NewsApiDtoFactory.php

View workflow job for this annotation

GitHub Actions / phpstan

Ignored error pattern #^Cannot call method getId\(\) on mixed\.$# in path /home/runner/work/SuluNewsBundle/SuluNewsBundle/Api/Factory/NewsApiDtoFactory.php was not matched in reported errors.

Check failure on line 1 in Api/Factory/NewsApiDtoFactory.php

View workflow job for this annotation

GitHub Actions / phpstan

Ignored error pattern #^Parameter \#1 \$id of class TheCadien\\Bundle\\SuluNewsBundle\\Api\\News constructor expects int, int\|null given\.$# in path /home/runner/work/SuluNewsBundle/SuluNewsBundle/Api/Factory/NewsApiDtoFactory.php was not matched in reported errors.

namespace TheCadien\Bundle\SuluNewsBundle\Api\Factory;

use TheCadien\Bundle\SuluNewsBundle\Api\News;
use TheCadien\Bundle\SuluNewsBundle\Entity\News as NewsEntity;

final class NewsApiDtoFactory
{
public function generate(NewsEntity $entity, string $locale): News
{
return new News(
id: $entity->getId(),
title: $entity->getTitle(),

Check failure on line 14 in Api/Factory/NewsApiDtoFactory.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter $title of class TheCadien\Bundle\SuluNewsBundle\Api\News constructor expects string, string|null given.
teaser: $entity->getTeaser(),
content: $entity->getContent(),
enabled: $entity->isEnabled(),
publishedAt: $entity->getPublishedAt(),
route: $entity->getRoute()?->getPath(),
tags: $entity->getTagNameArray(),
header: [
'id' => $entity->getHeader()?->getId(),
],
authored: $entity->getCreated(),
created: $entity->getCreated(),
changed: $entity->getChanged(),
author: $entity->getCreator()?->getId(),
ext: $entity->getSeo(),
locale: $locale
);
}
}
224 changes: 20 additions & 204 deletions Api/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,211 +13,27 @@

namespace TheCadien\Bundle\SuluNewsBundle\Api;

use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\VirtualProperty;
use Sulu\Component\Rest\ApiWrapper;
use TheCadien\Bundle\SuluNewsBundle\Entity\News as NewsEntity;
use Symfony\Component\Validator\Constraints as Assert;

/**
* The News class which will be exported to the API.
*
* @ExclusionPolicy("all")
*/
class News extends ApiWrapper
final class News
{
public function __construct(NewsEntity $contact, $locale)
{
// @var NewsEntity entity
$this->entity = $contact;
$this->locale = $locale;
}

/**
* Get id.
*
* @VirtualProperty
*
* @SerializedName("id")
* @Groups({"fullNews"})
*/
public function getId(): ?int
{
return $this->entity->getId();
}

/**
* @VirtualProperty
*
* @SerializedName("title")
* @Groups({"fullNews"})
*/
public function getTitle(): ?string
{
return $this->entity?->getTitle();
}

/**
* @VirtualProperty
*
* @SerializedName("teaser")
* @Groups({"fullNews"})
*/
public function getTeaser(): ?string
{
return $this->entity->getTeaser();
}

/**
* @VirtualProperty
*
* @SerializedName("content")
* @Groups({"fullNews"})
*/
public function getContent(): array
{
if (!$this->entity->getContent()) {
return [];
}

return $this->entity->getContent();
}

/**
* @VirtualProperty
*
* @SerializedName("enabled")
* @Groups({"fullNews"})
*/
public function isEnabled(): bool
{
return $this->entity?->isEnabled();
}

/**
* @VirtualProperty
*
* @SerializedName("publishedAt")
* @Groups({"fullNews"})
*/
public function getPublishedAt(): ?\DateTime
{
return $this->entity?->getPublishedAt();
}

/**
* @VirtualProperty
*
* @SerializedName("route")
* @Groups({"fullNews"})
*/
public function getRoutePath(): ?string
{
if ($this->entity?->getRoute()) {
return $this->entity->getRoute()?->getPath();
}

return '';
}

/**
* Get tags.
*
* @VirtualProperty
*
* @SerializedName("tags")
* @Groups({"fullNews"})
*/
public function getTags(): array
{
return $this->entity->getTagNameArray();
}

/**
* Get the contacts avatar and return the array of different formats.
*
* @VirtualProperty
*
* @SerializedName("header")
* @Groups({"fullNews"})
*/
public function getHeader(): array
{
if ($this->entity->getHeader()) {
return [
'id' => $this->entity->getHeader()->getId(),
];
}

return [];
}

/**
* Get tags.
*
* @VirtualProperty
*
* @SerializedName("authored")
* @Groups({"fullNews"})
*/
public function getAuthored(): \DateTime
{
return $this->entity->getCreated();
}

/**
* Get tags.
*
* @VirtualProperty
*
* @SerializedName("created")
* @Groups({"fullNews"})
*/
public function getCreated(): \DateTime
{
return $this->entity->getCreated();
}

/**
* Get tags.
*
* @VirtualProperty
*
* @SerializedName("changed")
* @Groups({"fullNews"})
*/
public function getChanged(): \DateTime
{
return $this->entity->getChanged();
}

/**
* Get tags.
*
* @VirtualProperty
*
* @SerializedName("author")
* @Groups({"fullNews"})
*/
public function getAuthor(): ?int
{
return $this->entity?->getCreator()?->getId();
}

/**
* Get tags.
*
* @VirtualProperty
*
* @SerializedName("ext")
* @Groups({"fullNews"})
*/
public function getSeo(): array
{
$seo = ['seo'];
$seo['seo'] = $this->getEntity()->getSeo();

return $seo;
public function __construct(
#[Assert\NotBlank(groups: ['edit'])]
public ?int $id,
public string $title,
public ?string $teaser,
public ?array $content,

Check failure on line 25 in Api/News.php

View workflow job for this annotation

GitHub Actions / phpstan

Property TheCadien\Bundle\SuluNewsBundle\Api\News::$content type has no value type specified in iterable type array.
public ?bool $enabled,
public ?\DateTime $publishedAt = null,
public ?string $route,
public ?array $tags,

Check failure on line 29 in Api/News.php

View workflow job for this annotation

GitHub Actions / phpstan

Property TheCadien\Bundle\SuluNewsBundle\Api\News::$tags type has no value type specified in iterable type array.
public ?array $header,

Check failure on line 30 in Api/News.php

View workflow job for this annotation

GitHub Actions / phpstan

Property TheCadien\Bundle\SuluNewsBundle\Api\News::$header type has no value type specified in iterable type array.
public ?\DateTime $authored = null,
public ?\DateTime $created = null,
public ?\DateTime $changed = null,
public ?int $author,
public ?string $ext,
public ?string $locale = null
) {
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check failure on line 1 in Common/DoctrineListRepresentationFactory.php

View workflow job for this annotation

GitHub Actions / phpstan

Ignored error pattern #^Parameter \#2 \$locale of method TheCadien\\Bundle\\SuluNewsBundle\\Common\\DoctrineListRepresentationFactory\:\:addHeader\(\) expects string, mixed given\.$# in path /home/runner/work/SuluNewsBundle/SuluNewsBundle/Common/DoctrineListRepresentationFactory.php was not matched in reported errors.

Check failure on line 1 in Common/DoctrineListRepresentationFactory.php

View workflow job for this annotation

GitHub Actions / phpstan

Ignored error pattern #^Parameter \#2 \$value of method Sulu\\Component\\Rest\\ListBuilder\\ListBuilderInterface\:\:where\(\) expects string, mixed given\.$# in path /home/runner/work/SuluNewsBundle/SuluNewsBundle/Common/DoctrineListRepresentationFactory.php was not matched in reported errors.

declare(strict_types=1);

Expand All @@ -11,7 +11,7 @@
* with this source code in the file LICENSE.
*/

namespace TheCadien\Bundle\SuluNewsBundle\Admin;
namespace TheCadien\Bundle\SuluNewsBundle\Common;

use Sulu\Bundle\MediaBundle\Media\Manager\MediaManagerInterface;
use Sulu\Component\Rest\ListBuilder\Doctrine\DoctrineListBuilderFactoryInterface;
Expand Down Expand Up @@ -67,10 +67,6 @@
);
}

/**
* Takes an array of contacts and resets the avatar containing the media id with
* the actual urls to the avatars thumbnail.
*/
private function addHeader(array $news, string $locale): array
{
$ids = \array_filter(\array_column($news, 'header'));
Expand Down
3 changes: 2 additions & 1 deletion Content/NewsDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

use JMS\Serializer\Context;
use JMS\Serializer\SerializationContext;
use Sulu\Component\SmartContent\Configuration\ProviderConfigurationInterface;
use Sulu\Component\SmartContent\Orm\BaseDataProvider;

class NewsDataProvider extends BaseDataProvider
{
public function getConfiguration()
{
if (null === $this->configuration) {
if (!$this->configuration instanceof ProviderConfigurationInterface) {
$this->configuration = self::createConfigurationBuilder()
->enableLimit()
->enablePagination()
Expand Down
Loading
Loading