Skip to content

Commit

Permalink
Merge branch 'release/2.6.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu2607 committed Jun 14, 2024
2 parents a2b3a94 + 0e00208 commit 4fc921b
Show file tree
Hide file tree
Showing 27 changed files with 343 additions and 110 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.6.0 (14/06/2024)

+ Compatible with Sulu 2.6 and Symfony 6.4

## 2.4.15 (10/02/2023)

- fix pagination
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"sulu/sulu": "^2.4",
"symfony/config": "^4.4 || ^5.0",
"pixelopen/sulu-blockbundle": "^2.4 || ^2.5",
"symfony/dependency-injection": "^4.4 || ^5.0",
"symfony/framework-bundle": "^4.4 || ^5.0",
"symfony/http-foundation": "^4.4 || ^5.0",
"symfony/http-kernel": "^4.4 || ^5.0"
"symfony/config": "^5.0 || ^6.0",
"pixelopen/sulu-blockbundle": "^2.5 || ^2.6",
"symfony/dependency-injection": "^5.0 || ^6.0",
"symfony/framework-bundle": "^5.0 || ^6.0",
"symfony/http-foundation": "^5.0 || ^6.0",
"symfony/http-kernel": "^5.0 || ^6.0"
},
"require-dev": {
"dantleech/phpcr-migrations-bundle": "^1.3",
Expand Down
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
level: 6

checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false

paths:
- src

ignoreErrors:
- '#Negated boolean expression is always false#'
- '#Unable to resolve the template type T in call#'
113 changes: 108 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Sulu news bundle

![GitHub release (with filter)](https://img.shields.io/github/v/release/Pixel-Open/sulu-newsbundle?style=for-the-badge)
[![Dependency](https://img.shields.io/badge/sulu-2.5-cca000.svg?style=for-the-badge)](https://sulu.io/)

## Presentation
A Sulu bundle to manage the news of your website.

## Requirements

* PHP >= 7.4
* PHP >= 8.0
* Sulu >= 2.4.*
* Symfony >= 5.4
* Composer

## Features
* List view of News (smart content)
Expand All @@ -19,7 +25,6 @@
* Automation
* SEO


## Installation

### Install the bundle
Expand All @@ -28,9 +33,7 @@ Execute the following [composer](https://getcomposer.org/) command to add the bu
project:

```bash

composer require pixeldev/sulu-newsbundle --with-all-dependencies

composer require pixelopen/sulu-newsbundle --with-all-dependencies
```

### Enable the bundle
Expand Down Expand Up @@ -60,3 +63,103 @@ news.news_api:
name_prefix: news.
```
## Use
### Add/Edit a news
Go to the "News" section in the administration interface. Then, click on "Add".
Fill the fields that are needed for your use.
Here is the list of the fields:
* Title (mandatory)
* URL (mandatory and filled automatically according to the title)
* Published at (manually filled)
* Cover
* Category (mandatory)
* Content
The "Content" field is a block content type. The different type of block come from the [Sulu Block Bundle](https://github.com/Pixel-Developpement/sulu-block-bundle)
Once you finished, click on "Save"
Your news is not visible on the website yet. In order to do that, click on "Publish?". It should be now visible for visitors.
To edit a news, simply click on the pencil at the left of the news you wish to edit.
### Categories
As you may have seen in the previous section, a news needs a category. These categories need to be created in a very specific way:
* You **must** create a root category which **must** have its key named "news"
* Then, under this root category, you create all the news categories you need
### Remove/Restore a gallery
There are two ways to remove a news:
* Check every news you want to remove and then click on "Delete"
* Go to the detail of a news (see the "Add/Edit a news" section) and click on "Delete".
In both cases, the news will be put in the trash.
To access the trash, go to the "Settings" and click on "Trash".
To restore a news, click on the clock at the left. Confirm the restore. You will be redirected to the detail of the news you restored.
To remove permanently a news, check all the news you want to remove and click on "Delete".
## Settings
This bundle comes with settings. There is only one setting, it's the configuration of a default image.
To access the bundle settings, go to "Settings > News management".
## Twig extension
There are several twig functions in order to help you use the news and settings on your website:
**get_latest_news(limit, local)**: returns the latest news. It takes two parameters:
* limit: represents the number of the latest news to display. If no limit is provided, the default value is 3
* locale: the locale in which the news should be retrieved. If no local is provided, the default value is 'fr'
Example of use:
```twig
<div class="w-full flex flex-row gap-6 justify-between">
{% set news = get_latest_news(4, app.request.locale) %}
{% for new in news %}
<div class="containerAvis bg-white rounded-xl p-6 w-1/4">
<a href="{{ sulu_content_path(new.routePath) }}" class="no-underline">
{% if new.cover.id is defined %}
{% set cover = sulu_resolve_media(new.cover.id, 'fr') %}
<img src="{{ cover.thumbnails["991x"] }}" alt="{{ new.title }}"
class="w-full h-40 object-cover object-center bg-black mt-0 mb-4">
{% endif %}
<h3 class="block text-center text-base font-bold">{{ new.title }}</h3>
<p class="block text-center">{{ new.publishedAt|date("d/m/Y") }} {#- {{ new.category }} #}</p>
</a>
</div>
{% endfor %}
</div>
```

**get_latest_news_html(limit, locale)**: same as get_latest_news but it renders a view instead. It takes two parameters:
* limit: represents the number of the latest news to display. If no limit is provided, the default value is 3
* locale: the locale in which the news should be retrieved. If no local is provided, the default value is 'fr'

Example of use:
```twig
<div>
{{ get_latest_news_html(4, app.request.locale) }}
</div>
```

**news_settings()**: returns the settings of the bundle. No parameters are required.

Example of use:

```twig
{% set newsSettings = news_settings() %}
{% if news.cover is not empty %}
{% set cover = sulu_resolve_media(news.cover.id, 'en' %}
<img src="{{ cover.thumbnails['991x'] }}" alt="{{ news.name }}">
{% else %}
{% set default = sulu_resolve_media(newsSettings.defaultImage.id, 'en' %}
<img src="{{ default.thumbnails['991x'] }}" alt="Default news image">
{% endif %}
```

## Contributing
You can contribute to this bundle. The only thing you must do is respect the coding standard we implement.
You can find them in the `ecs.php` file.
27 changes: 19 additions & 8 deletions src/Content/NewsDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Pixel\NewsBundle\Content;

use Doctrine\ORM\EntityManagerInterface;
use Pixel\NewsBundle\Entity\News;
use Pixel\NewsBundle\Repository\NewsRepository;
use Sulu\Component\Content\Compat\PropertyParameter;
use Sulu\Component\Serializer\ArraySerializerInterface;
use Sulu\Component\SmartContent\DataProviderResult;
use Sulu\Component\SmartContent\ItemInterface;
Expand All @@ -17,12 +17,12 @@ class NewsDataProvider extends BaseDataProvider
{
private RequestStack $requestStack;

private EntityManagerInterface $entityManager;
private NewsRepository $newsRepository;

public function __construct(DataProviderRepositoryInterface $repository, ArraySerializerInterface $serializer, RequestStack $requestStack, EntityManagerInterface $entityManager)
public function __construct(DataProviderRepositoryInterface $repository, ArraySerializerInterface $serializer, RequestStack $requestStack, NewsRepository $newsRepository)
{
parent::__construct($repository, $serializer);
$this->entityManager = $entityManager;
$this->newsRepository = $newsRepository;
$this->requestStack = $requestStack;
}

Expand Down Expand Up @@ -50,6 +50,15 @@ public function getConfiguration()
return $this->configuration;
}

/**
* @param array<mixed> $filters
* @param array<mixed> $propertyParameter
* @param array<mixed> $options
* @param int $limit
* @param int $page
* @param int $pageSize
* @return DataProviderResult
*/
public function resolveResourceItems(
array $filters,
array $propertyParameter,
Expand All @@ -61,12 +70,13 @@ public function resolveResourceItems(
$locale = $options['locale'];
$request = $this->requestStack->getCurrentRequest();
$options['page'] = $request->get('p');
$news = $this->entityManager->getRepository(News::class)->findByFilters($filters, $page, $pageSize, $limit, $locale, $options);
return new DataProviderResult($news, $this->entityManager->getRepository(News::class)->hasNextPage($filters, $page, $pageSize, $limit, $locale, $options));
$news = $this->newsRepository->findByFilters($filters, $page, $pageSize, $limit, $locale, $options);
return new DataProviderResult($news, $this->newsRepository->hasNextPage($filters, $page, $pageSize, $limit, $locale, $options));
}

/**
* Decorates result as data item.
* @param array<mixed> $data
*
* @return ItemInterface[]
*/
Expand All @@ -84,8 +94,9 @@ function ($item) {
* Returns additional options for query creation.
*
* @param PropertyParameter[] $propertyParameter
* @param array<mixed> $options
*
* @return array
* @return array<mixed>
*/
protected function getOptions(array $propertyParameter, array $options = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/Content/Type/NewsSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Pixel\NewsBundle\Content\Type;

use Doctrine\ORM\EntityManagerInterface;
use Pixel\newsBundle\Entity\News;
use Pixel\NewsBundle\Entity\News;
use Sulu\Component\Content\Compat\PropertyInterface;
use Sulu\Component\Content\SimpleContentType;

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Admin/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getAction(int $id, Request $request): Response
return $this->handleView($this->view($item));
}

protected function load(int $id, Request $request, $defaultLocal = null): ?News
protected function load(int $id, Request $request, string $defaultLocal = null): ?News
{
return $this->repository->findById($id, ($defaultLocal) ? $defaultLocal : (string) $this->getLocale($request));
}
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/Admin/SettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public function putAction(Request $request): Response
return $this->handleView($this->view($applicationSetting));
}

/**
* @param array<mixed> $data
*/
public function mapDataToEntity(array $data, Setting $entity): void
{
$defaultImageId = $data['defaultImage']['id'] ?? null;
Expand Down
Loading

0 comments on commit 4fc921b

Please sign in to comment.