[EVENT][AddFeedActions] Add bool param which denotes whether the feed is empty. [PLUGIN][NoteTypeFeedFilter] Don't show filters if the feed is empty
This commit is contained in:
parent
d5a6fa924b
commit
8fa04bb47d
|
@ -14,7 +14,7 @@
|
||||||
<h1>{{ page_title | trans }}</h1>
|
<h1>{{ page_title | trans }}</h1>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<nav class="feed-actions">
|
<nav class="feed-actions">
|
||||||
{% for block in handle_event('AddFeedActions', app.request) %}
|
{% for block in handle_event('AddFeedActions', app.request, notes is defined and notes is not empty) %}
|
||||||
{{ block | raw }}
|
{{ block | raw }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -124,37 +124,39 @@ class NoteTypeFeedFilter extends Plugin
|
||||||
/**
|
/**
|
||||||
* Draw the media feed navigation.
|
* Draw the media feed navigation.
|
||||||
*/
|
*/
|
||||||
public function onAddFeedActions(Request $request, &$res): bool
|
public function onAddFeedActions(Request $request, bool $is_not_empty, &$res): bool
|
||||||
{
|
{
|
||||||
$qs = [];
|
if ($is_not_empty) {
|
||||||
parse_str($request->getQueryString(), $qs);
|
$qs = [];
|
||||||
if (\array_key_exists('p', $qs) && \is_string($qs['p'])) {
|
parse_str($request->getQueryString(), $qs);
|
||||||
unset($qs['p']);
|
if (\array_key_exists('p', $qs) && \is_string($qs['p'])) {
|
||||||
}
|
unset($qs['p']);
|
||||||
$types = $this->normalizeTypesList(\is_null($request->get('note-types')) ? [] : explode(',', $request->get('note-types')), add_missing: false);
|
}
|
||||||
$ftypes = array_flip($types);
|
$types = $this->normalizeTypesList(\is_null($request->get('note-types')) ? [] : explode(',', $request->get('note-types')), add_missing: false);
|
||||||
|
$ftypes = array_flip($types);
|
||||||
|
|
||||||
$tabs = [
|
$tabs = [
|
||||||
'all' => [
|
'all' => [
|
||||||
'active' => empty($types) || $types === self::ALLOWED_TYPES,
|
'active' => empty($types) || $types === self::ALLOWED_TYPES,
|
||||||
'url' => '?' . http_build_query(['note-types' => implode(',', self::ALLOWED_TYPES)], '', '&', \PHP_QUERY_RFC3986),
|
'url' => '?' . http_build_query(['note-types' => implode(',', self::ALLOWED_TYPES)], '', '&', \PHP_QUERY_RFC3986),
|
||||||
'icon' => 'All',
|
'icon' => 'All',
|
||||||
],
|
],
|
||||||
];
|
|
||||||
|
|
||||||
foreach (self::ALLOWED_TYPES as $allowed_type) {
|
|
||||||
$active = \array_key_exists($allowed_type, $ftypes);
|
|
||||||
$new_types = $this->normalizeTypesList([($active ? '!' : '') . $allowed_type, ...$types], add_missing: false);
|
|
||||||
$new_qs = $qs;
|
|
||||||
$new_qs['note-types'] = implode(',', $new_types);
|
|
||||||
$tabs[$allowed_type] = [
|
|
||||||
'active' => $active,
|
|
||||||
'url' => '?' . http_build_query($new_qs, '', '&', \PHP_QUERY_RFC3986),
|
|
||||||
'icon' => $allowed_type,
|
|
||||||
];
|
];
|
||||||
}
|
|
||||||
|
|
||||||
$res[] = Formatting::twigRenderFile('NoteTypeFeedFilter/tabs.html.twig', ['tabs' => $tabs]);
|
foreach (self::ALLOWED_TYPES as $allowed_type) {
|
||||||
|
$active = \array_key_exists($allowed_type, $ftypes);
|
||||||
|
$new_types = $this->normalizeTypesList([($active ? '!' : '') . $allowed_type, ...$types], add_missing: false);
|
||||||
|
$new_qs = $qs;
|
||||||
|
$new_qs['note-types'] = implode(',', $new_types);
|
||||||
|
$tabs[$allowed_type] = [
|
||||||
|
'active' => $active,
|
||||||
|
'url' => '?' . http_build_query($new_qs, '', '&', \PHP_QUERY_RFC3986),
|
||||||
|
'icon' => $allowed_type,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$res[] = Formatting::twigRenderFile('NoteTypeFeedFilter/tabs.html.twig', ['tabs' => $tabs]);
|
||||||
|
}
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user