-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathArticleNavigationButton.php
More file actions
69 lines (59 loc) · 2.92 KB
/
Copy pathArticleNavigationButton.php
File metadata and controls
69 lines (59 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace FriendsOfRedaxo\QuickNavigation\Button;
use rex_article;
use rex_be_controller;
use rex_category;
use rex_clang;
use rex_string;
use rex_url;
use function count;
class ArticleNavigationButton implements ButtonInterface
{
public function get(): string
{
// Initialisiere die Navigationspfeile nicht
$prev = '';
$next = '';
if (rex_be_controller::getCurrentPage() == 'content/edit') {
$cat = rex_category::getCurrent();
$articles = $cat ? $cat->getArticles() : rex_article::getRootArticles();
// Zeige die Navigationspfeile nur an, wenn mehr als der Startartikel vorhanden ist
if (count($articles) > 1) {
// Initialisiere Buttons als deaktiviert
$prev = '<button class="btn btn-default" disabled><span class="fa fa-chevron-left"></span></button>';
$next = '<button class="btn btn-default" disabled><span class="fa fa-chevron-right"></span></button>';
$article_stack = [];
foreach ($articles as $article) {
$article_stack[] = $article->getId();
}
$index = array_search(rex_request('article_id'), $article_stack);
if ($index !== false) {
// Vorherigen Artikel aktivieren, wenn möglich
if ($index - 1 >= 0) {
$article = rex_article::get($article_stack[$index - 1]);
$attributes = [
'class' => 'btn btn-default',
'href' => rex_url::backendPage('content/edit', ['mode' => 'edit', 'clang' => rex_clang::getCurrentId(), 'category_id' => rex_request('category_id'), 'article_id' => $article->getId()]),
'title' => $article->getName()
];
$prev = '<a' . rex_string::buildAttributes($attributes). '><span class="fa fa-chevron-left"></span></a>';
}
// Nächsten Artikel aktivieren, wenn möglich
if ($index + 1 < count($article_stack)) {
$article = rex_article::get($article_stack[$index + 1]);
$attributes = [
'class' => 'btn btn-default',
'href' => rex_url::backendPage('content/edit', ['mode' => 'edit', 'clang' => rex_clang::getCurrentId(), 'category_id' => rex_request('category_id'), 'article_id' => $article->getId()]),
'title' => $article->getName()
];
$next = '<a' . rex_string::buildAttributes($attributes). '><span class="fa fa-chevron-right"></span></a>';
}
}
}
}
if ('' !== $prev && '' !== $next) {
return '<div class="btn-group">' . $prev . $next . '</div>';
}
return '';
}
}