Skip to content

Commit

Permalink
Merge branch 'release/2.6.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu2607 committed Dec 5, 2024
2 parents 4fc921b + d2dbd54 commit 22fcb3e
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 11 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.6.1 (05/12/2024)

+ Require Sulu 2.6 on composer
+ Add html block
+ Update readme

## 2.6.0 (14/06/2024)

+ Compatible with Sulu 2.6 and Symfony 6.4
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"require": {
"php": "^8.0",
"sulu/sulu": "^2.4",
"sulu/sulu": "^2.6",
"symfony/config": "^5.0 || ^6.0",
"pixelopen/sulu-blockbundle": "^2.5 || ^2.6",
"symfony/dependency-injection": "^5.0 || ^6.0",
Expand Down
11 changes: 6 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# 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/)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-green)](https://php.net/)
[![Minimum Sulu Version](https://img.shields.io/badge/sulu-%3E%3D%202.6-green)](https://symfony.com)
[![GitHub release](https://img.shields.io/github/v/release/Pixel-Open/sulu-newsbundle)](https://github.com/Pixel-Open/cloudflare-turnstile-bundle/releases)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Pixel-Open_sulu-blockbundle&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Pixel-Open_sulu-blockbundle)


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

## Requirements

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

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

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

### Enable the bundle
Expand Down
14 changes: 13 additions & 1 deletion src/Admin/NewsAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactoryInterface;
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection;
use Sulu\Bundle\AutomationBundle\Admin\View\AutomationViewBuilderFactoryInterface;
use Sulu\Bundle\ReferenceBundle\Infrastructure\Sulu\Admin\View\ReferenceViewBuilderFactoryInterface;
use Sulu\Component\Security\Authorization\PermissionTypes;
use Sulu\Component\Security\Authorization\SecurityCheckerInterface;
use Sulu\Component\Webspace\Manager\WebspaceManagerInterface;
Expand Down Expand Up @@ -44,18 +45,22 @@ class NewsAdmin extends Admin

private AutomationViewBuilderFactoryInterface $automationViewBuilderFactory;

private ReferenceViewBuilderFactoryInterface $referenceViewBuilderFactory;

public function __construct(
ViewBuilderFactoryInterface $viewBuilderFactory,
SecurityCheckerInterface $securityChecker,
WebspaceManagerInterface $webspaceManager,
ActivityViewBuilderFactoryInterface $activityViewBuilderFactory,
AutomationViewBuilderFactoryInterface $automationViewBuilderFactory
AutomationViewBuilderFactoryInterface $automationViewBuilderFactory,
ReferenceViewBuilderFactoryInterface $referenceViewBuilderFactory
) {
$this->viewBuilderFactory = $viewBuilderFactory;
$this->securityChecker = $securityChecker;
$this->webspaceManager = $webspaceManager;
$this->activityViewBuilderFactory = $activityViewBuilderFactory;
$this->automationViewBuilderFactory = $automationViewBuilderFactory;
$this->referenceViewBuilderFactory = $referenceViewBuilderFactory;
}

public function configureNavigationItems(NavigationItemCollection $navigationItemCollection): void
Expand Down Expand Up @@ -182,6 +187,13 @@ public function configureViews(ViewCollection $viewCollection): void
->setDefaultLocale($locales[0])
->setParent(self::EDIT_FORM_VIEW)
);

if ($this->referenceViewBuilderFactory->hasReferenceListPermission()) {
$viewCollection->add(
$this->referenceViewBuilderFactory->createReferenceListViewBuilder(static::EDIT_FORM_VIEW . ".insights.references", "/references", News::RESOURCE_KEY)
->setParent(static::EDIT_FORM_VIEW)
);
}
}
}

Expand Down
20 changes: 19 additions & 1 deletion src/Content/Type/NewsSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

use Doctrine\ORM\EntityManagerInterface;
use Pixel\NewsBundle\Entity\News;
use Sulu\Bundle\ReferenceBundle\Application\Collector\ReferenceCollectorInterface;
use Sulu\Bundle\ReferenceBundle\Infrastructure\Sulu\ContentType\ReferenceContentTypeInterface;
use Sulu\Component\Content\Compat\PropertyInterface;
use Sulu\Component\Content\SimpleContentType;

class NewsSelection extends SimpleContentType
class NewsSelection extends SimpleContentType implements ReferenceContentTypeInterface
{
protected EntityManagerInterface $entityManager;

Expand Down Expand Up @@ -52,4 +54,20 @@ public function getViewData(PropertyInterface $property): array
'ids' => $property->getValue(),
];
}

public function getReferences(PropertyInterface $property, ReferenceCollectorInterface $referenceCollector, string $propertyPrefix = ''): void
{
$data = $property->getValue();
if (!isset($data) || !is_array($data)) {
return;
}

foreach ($data as $id) {
$referenceCollector->addReference(
News::RESOURCE_KEY,
(string) $id,
$propertyPrefix . $property->getName()
);
}
}
}
19 changes: 18 additions & 1 deletion src/Content/Type/SingleNewsSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

use Doctrine\ORM\EntityManagerInterface;
use Pixel\NewsBundle\Entity\News;
use Sulu\Bundle\ReferenceBundle\Application\Collector\ReferenceCollectorInterface;
use Sulu\Bundle\ReferenceBundle\Infrastructure\Sulu\ContentType\ReferenceContentTypeInterface;
use Sulu\Bundle\WebsiteBundle\ReferenceStore\ReferenceStoreInterface;
use Sulu\Component\Content\Compat\PropertyInterface;
use Sulu\Component\Content\SimpleContentType;

class SingleNewsSelection extends SimpleContentType
class SingleNewsSelection extends SimpleContentType implements ReferenceContentTypeInterface
{
protected EntityManagerInterface $entityManager;

Expand Down Expand Up @@ -40,4 +43,18 @@ public function getViewData(PropertyInterface $property): array
'id' => $property->getValue(),
];
}

public function getReferences(PropertyInterface $property, ReferenceCollectorInterface $referenceCollector, string $propertyPrefix = ''): void
{
$data = $property->getValue();
if (!isset($data) || !is_int($data)) {
return;
}

$referenceCollector->addReference(
News::RESOURCE_KEY,
(string) $data,
$propertyPrefix . $property->getName()
);
}
}
3 changes: 1 addition & 2 deletions src/Controller/Website/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function indexAction(News $news, array $attributes = [], bool $preview =
$parameters
);
} elseif ($preview) {
$content = $this->renderPreview(
$content = $this->renderPreview(
'@News/news.html.twig',
$parameters
);
Expand All @@ -68,7 +68,6 @@ public function indexAction(News $news, array $attributes = [], bool $preview =
'@News/news.html.twig',
$parameters
);

}

return new Response((string) $content);
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/forms/news_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<xi:include href="sulu-block-bundle://blocks/three_columns.xml"/>
<xi:include href="sulu-block-bundle://blocks/highlight.xml"/>
<xi:include href="sulu-block-bundle://blocks/video_text.xml"/>
<xi:include href="sulu-block-bundle://blocks/code_html.xml"/>
</types>
</block>
</properties>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<argument type="service" id="sulu_core.webspace.webspace_manager"/>
<argument type="service" id="sulu_activity.activity_list_view_builder_factory"/>
<argument type="service" id="sulu_automation.automation_view_builder_factory"/>
<argument type="service" id="sulu_reference.reference_list_view_builder_factory"/>
<tag name="sulu.admin"/>
<tag name="sulu.context" context="admin"/>
</service>
Expand Down

0 comments on commit 22fcb3e

Please sign in to comment.