Skip to content

Commit

Permalink
Merge pull request #1311 from bolt/feature/badges-for-special-pages
Browse files Browse the repository at this point in the history
Feature/badges for special pages
  • Loading branch information
bobdenotter authored Apr 19, 2020
2 parents ac246f9 + 3e7ea96 commit 1d2039f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 12 deletions.
6 changes: 6 additions & 0 deletions assets/js/app/listing/Components/Table/Row/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
>
{{ record.extras.title | trim(62) | raw }}
</a>
<span
v-if="record.extras.feature"
class="badge"
:class="`badge-${record.extras.feature}`"
>{{ record.extras.feature }}</span
>
<span class="listing__row--item-title-excerpt">{{
record.extras.excerpt | raw
}}</span>
Expand Down
21 changes: 21 additions & 0 deletions assets/scss/modules/base/_status.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@
background: var(--status-timed);
}
}

.badge-homepage,
.badge-404,
.badge-maintenance {
font-weight: normal;
vertical-align: middle;
margin-top: -0.4em;
text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.4);
}

.badge-homepage {
background: $secondary;
}

.badge-404 {
background: $warning;
}

.badge-maintenance {
background: $tertiary;
}
1 change: 1 addition & 0 deletions src/Entity/ContentExtrasTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getExtras(): array
'icon' => $this->getIcon(),
'name' => $this->getDefinition()->get('name'),
'singular_name' => $this->getDefinition()->get('singular_name'),
'feature' => $this->contentExtension->getSpecialFeature($content),
]);
}
}
69 changes: 57 additions & 12 deletions src/Twig/ContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function getFilters(): array
new TwigFilter('has_path', [$this, 'hasPath']),
new TwigFilter('allow_twig', [$this, 'allowTwig'], $env),
new TwigFilter('status_options', [$this, 'statusOptions']),
new TwigFilter('feature', [$this, 'getSpecialFeature']),
];
}

Expand Down Expand Up @@ -370,18 +371,6 @@ public function getLink(Content $content, bool $canonical = false): ?string
return $this->generateLink('record', $params, $canonical);
}

public function isHomepage(Content $content): bool
{
$homepageSetting = explode('/', $this->config->get('general/homepage'));

if (empty($homepageSetting[1])) {
return false;
}

return ($homepageSetting[0] === $content->getContentTypeSingularSlug() || $homepageSetting[0] === $content->getContentTypeSlug()) &&
($homepageSetting[1] === $content->getSlug() || $homepageSetting[1] === (string) $content->getId());
}

public function getEditLink(Content $content): ?string
{
if ($content->getId() === null || ! $this->security->getUser()) {
Expand Down Expand Up @@ -699,4 +688,60 @@ public function statusOptions(Content $record)

return $options;
}

public function getSpecialFeature(Content $record): string
{
if ($this->isHomepage($record)) {
return 'homepage';
}

if ($this->is404($record)) {
return '404';
}

if ($this->isMaintenance($record)) {
return 'maintenance';
}

return '';
}

public function isHomepage(Content $content): bool
{
return $this->isSpecialpage($content, 'homepage');
}

public function is404(Content $content): bool
{
return $this->isSpecialpage($content, 'notfound');
}

public function isMaintenance(Content $content): bool
{
return $this->isSpecialpage($content, 'maintenance');
}

private function isSpecialpage(Content $content, string $type): bool
{
$configSetting = $this->config->get('general/' . $type);

if (! is_iterable($configSetting)) {
$configSetting = (array) $configSetting;
}

foreach ($configSetting as $item) {
$item = explode('/', $item);

if (empty($item[1])) {
continue;
}

if (($item[0] === $content->getContentTypeSingularSlug() || $item[0] === $content->getContentTypeSlug()) &&
($item[1] === $content->getSlug() || $item[1] === (string) $content->getId())) {
return true;
}
}

return false;
}
}

0 comments on commit 1d2039f

Please sign in to comment.