-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # CHANGELOG.md # calendar-bundle/contao/languages/it/tl_module.xlf # core-bundle/config/listener.yaml # core-bundle/contao/languages/it/default.xlf # core-bundle/contao/languages/it/tl_article.xlf # core-bundle/contao/languages/it/tl_content.xlf # core-bundle/contao/languages/it/tl_maintenance.xlf # core-bundle/contao/languages/it/tl_member.xlf # core-bundle/contao/languages/it/tl_module.xlf # core-bundle/contao/languages/it/tl_page.xlf # core-bundle/contao/languages/it/tl_theme.xlf # core-bundle/contao/languages/it/tl_user.xlf # core-bundle/contao/languages/sl/default.xlf # core-bundle/contao/languages/sl/exception.xlf # core-bundle/contao/languages/sl/explain.xlf # core-bundle/contao/languages/sl/modules.xlf # core-bundle/contao/languages/sl/tl_article.xlf # core-bundle/contao/languages/sl/tl_content.xlf # core-bundle/contao/languages/sl/tl_files.xlf # core-bundle/contao/languages/sl/tl_image_size.xlf # core-bundle/contao/languages/sl/tl_log.xlf # core-bundle/contao/languages/sl/tl_maintenance.xlf # core-bundle/contao/languages/sl/tl_member.xlf # core-bundle/contao/languages/sl/tl_module.xlf # core-bundle/contao/languages/sl/tl_page.xlf # core-bundle/contao/languages/sl/tl_settings.xlf # core-bundle/contao/languages/sl/tl_theme.xlf # core-bundle/contao/languages/sl/tl_user.xlf # news-bundle/contao/languages/it/tl_module.xlf
- Loading branch information
Showing
88 changed files
with
1,248 additions
and
852 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 0 additions & 102 deletions
102
calendar-bundle/src/EventListener/InsertTagsListener.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Contao. | ||
* | ||
* (c) Leo Feyer | ||
* | ||
* @license LGPL-3.0-or-later | ||
*/ | ||
|
||
namespace Contao\CalendarBundle\InsertTag; | ||
|
||
use Contao\CalendarEventsModel; | ||
use Contao\CalendarFeedModel; | ||
use Contao\CoreBundle\DependencyInjection\Attribute\AsInsertTag; | ||
use Contao\CoreBundle\Framework\ContaoFramework; | ||
use Contao\CoreBundle\InsertTag\Exception\InvalidInsertTagException; | ||
use Contao\CoreBundle\InsertTag\InsertTagResult; | ||
use Contao\CoreBundle\InsertTag\OutputType; | ||
use Contao\CoreBundle\InsertTag\ResolvedInsertTag; | ||
use Contao\CoreBundle\InsertTag\Resolver\InsertTagResolverNestedResolvedInterface; | ||
use Contao\CoreBundle\Routing\ContentUrlGenerator; | ||
use Contao\StringUtil; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[AsInsertTag('event')] | ||
#[AsInsertTag('event_open')] | ||
#[AsInsertTag('event_url')] | ||
#[AsInsertTag('event_title')] | ||
#[AsInsertTag('event_teaser')] | ||
#[AsInsertTag('calendar_feed')] | ||
class EventInsertTag implements InsertTagResolverNestedResolvedInterface | ||
{ | ||
public function __construct( | ||
private readonly ContaoFramework $framework, | ||
private readonly ContentUrlGenerator $urlGenerator, | ||
) { | ||
} | ||
|
||
public function __invoke(ResolvedInsertTag $insertTag): InsertTagResult | ||
{ | ||
if ('calendar_feed' === $insertTag->getName()) { | ||
return $this->replaceCalendarFeedInsertTag($insertTag->getParameters()->get(0)); | ||
} | ||
|
||
return $this->replaceEventInsertTag( | ||
$insertTag->getName(), | ||
$insertTag->getParameters()->get(0), | ||
\array_slice($insertTag->getParameters()->all(), 1), | ||
); | ||
} | ||
|
||
private function replaceCalendarFeedInsertTag(string $feedId): InsertTagResult | ||
{ | ||
$this->framework->initialize(); | ||
|
||
$adapter = $this->framework->getAdapter(CalendarFeedModel::class); | ||
|
||
if (!$feed = $adapter->findById($feedId)) { | ||
return new InsertTagResult(''); | ||
} | ||
|
||
return new InsertTagResult(sprintf('%sshare/%s.xml', $feed->feedBase, $feed->alias), OutputType::url); | ||
} | ||
|
||
private function replaceEventInsertTag(string $insertTag, string $idOrAlias, array $arguments): InsertTagResult | ||
{ | ||
$this->framework->initialize(); | ||
|
||
$adapter = $this->framework->getAdapter(CalendarEventsModel::class); | ||
|
||
if (!$model = $adapter->findByIdOrAlias($idOrAlias)) { | ||
return new InsertTagResult(''); | ||
} | ||
|
||
$generateUrl = fn () => $this->urlGenerator->generate( | ||
$model, | ||
[], | ||
\in_array('absolute', $arguments, true) ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH, | ||
); | ||
|
||
return match ($insertTag) { | ||
'event' => new InsertTagResult( | ||
sprintf( | ||
'<a href="%s" title="%s"%s>%s</a>', | ||
StringUtil::specialcharsAttribute($generateUrl()), | ||
StringUtil::specialcharsAttribute($model->title), | ||
\in_array('blank', $arguments, true) ? ' target="_blank" rel="noreferrer noopener"' : '', | ||
$model->title, | ||
), | ||
OutputType::html, | ||
), | ||
'event_open' => new InsertTagResult( | ||
sprintf( | ||
'<a href="%s" title="%s"%s>', | ||
StringUtil::specialcharsAttribute($generateUrl()), | ||
StringUtil::specialcharsAttribute($model->title), | ||
\in_array('blank', $arguments, true) ? ' target="_blank" rel="noreferrer noopener"' : '', | ||
), | ||
OutputType::html, | ||
), | ||
'event_url' => new InsertTagResult( | ||
StringUtil::specialcharsAttribute($generateUrl()), | ||
OutputType::url, | ||
), | ||
'event_title' => new InsertTagResult($model->title), | ||
'event_teaser' => new InsertTagResult($model->teaser ?? '', OutputType::html), | ||
default => throw new InvalidInsertTagException(), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.