Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/badges for special pages #1311

Merged
merged 2 commits into from
Apr 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}