diff --git a/assets/js/app/editor/Components/Select.vue b/assets/js/app/editor/Components/Select.vue
index a83b6dfae..1f052f527 100644
--- a/assets/js/app/editor/Components/Select.vue
+++ b/assets/js/app/editor/Components/Select.vue
@@ -20,11 +20,11 @@
>
- {{ props.option.value }}
+ {{ props.option.value | raw }}
- {{ props.option.value }}
+ {{ props.option.value | raw }}
@@ -41,7 +41,7 @@
-
+
getDefinition()->get('title_format'), $locale);
+ $title = $this->contentHelper->get($content, $content->getDefinition()->get('title_format'), $locale);
} else {
$title = ContentHelper::getFieldBasedTitle($content, $locale);
}
@@ -241,7 +241,7 @@ public function getExcerpt($content, int $length = 280, bool $includeTitle = fal
}
if (ContentHelper::isSuitable($content, 'excerpt_format')) {
- $excerpt = ContentHelper::get($content, $content->getDefinition()->get('excerpt_format'));
+ $excerpt = $this->contentHelper->get($content, $content->getDefinition()->get('excerpt_format'));
} else {
$excerpt = $this->getFieldBasedExcerpt($content, $length, $includeTitle);
}
@@ -566,7 +566,7 @@ private function selectOptionsContentType(SelectField $field): LaravelCollection
foreach ($records as $record) {
$options[] = [
'key' => $record->getId(),
- 'value' => ContentHelper::get($record, $format),
+ 'value' => $this->contentHelper->get($record, $format),
];
}
diff --git a/src/Twig/RelatedExtension.php b/src/Twig/RelatedExtension.php
index 568c2141c..6403eabda 100644
--- a/src/Twig/RelatedExtension.php
+++ b/src/Twig/RelatedExtension.php
@@ -26,11 +26,15 @@ class RelatedExtension extends AbstractExtension
/** @var Query */
private $query;
- public function __construct(RelationRepository $relationRepository, Config $config, Query $query)
+ /** @var ContentHelper */
+ private $contentHelper;
+
+ public function __construct(RelationRepository $relationRepository, Config $config, Query $query, ContentHelper $contentHelper)
{
$this->relationRepository = $relationRepository;
$this->config = $config;
$this->query = $query;
+ $this->contentHelper = $contentHelper;
}
/**
@@ -151,7 +155,7 @@ public function getRelatedOptions(string $contentTypeSlug, ?string $order = null
foreach ($records as $record) {
$options[] = [
'key' => $record->getId(),
- 'value' => ContentHelper::get($record, $format),
+ 'value' => $this->contentHelper->get($record, $format),
];
}
diff --git a/src/Utils/ContentHelper.php b/src/Utils/ContentHelper.php
index 7fe38df34..f09695a3e 100644
--- a/src/Utils/ContentHelper.php
+++ b/src/Utils/ContentHelper.php
@@ -8,6 +8,7 @@
use Bolt\Configuration\Config;
use Bolt\Entity\Content;
use Bolt\Entity\Field\Excerptable;
+use Bolt\Twig\LocaleExtension;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -22,11 +23,15 @@ class ContentHelper
/** @var Config */
private $config;
- public function __construct(Canonical $canonical, RequestStack $requestStack, Config $config)
+ /** @var LocaleExtension */
+ private $localeExtension;
+
+ public function __construct(Canonical $canonical, RequestStack $requestStack, Config $config, LocaleExtension $localeExtension)
{
$this->canonical = $canonical;
$this->request = $requestStack->getCurrentRequest() ?? Request::createFromGlobals();
$this->config = $config;
+ $this->localeExtension = $localeExtension;
}
public function setCanonicalPath($record, ?string $locale = null): void
@@ -110,7 +115,7 @@ public static function isSuitable(Content $record, string $which = 'title_format
return false;
}
- public static function get(Content $record, string $format = '', string $locale = ''): string
+ public function get(Content $record, string $format = '', ?string $locale = null): string
{
if (empty($format)) {
$format = '{title} (№ {id}, {status})';
@@ -135,6 +140,22 @@ function ($match) use ($record, $locale) {
return $record->getAuthor();
}
+ if ($match[1] === 'publishedAt') {
+ return $this->localeExtension->localdate($record->getPublishedAt(), null, $locale);
+ }
+
+ if ($match[1] === 'modifiedAt') {
+ return $this->localeExtension->localdate($record->getModifiedAt(), null, $locale);
+ }
+
+ if ($match[1] === 'createdAt') {
+ return $this->localeExtension->localdate($record->getCreatedAt(), null, $locale);
+ }
+
+ if ($match[1] === 'depublishedAt') {
+ return $this->localeExtension->localdate($record->getDepublishedAt(), null, $locale);
+ }
+
if ($record->hasField($match[1])) {
$field = $record->getField($match[1]);
@@ -145,6 +166,15 @@ function ($match) use ($record, $locale) {
return $field;
}
+ if (array_key_exists($match[1], $record->getExtras())) {
+ // If it's the icon, return an html element
+ if ($match[1] === 'icon') {
+ return sprintf("", $record->getExtras()[$match[1]]);
+ }
+
+ return $record->getExtras()[$match[1]];
+ }
+
return '(unknown)';
},
$format