Views: Renamed SidebarSections to ViewBlocks

This commit is contained in:
Dan Brown
2026-08-07 16:00:04 +01:00
parent b462c67e2f
commit d4d90cc39c
35 changed files with 232 additions and 232 deletions
@@ -4,7 +4,7 @@ namespace BookStack\App\Providers;
use BookStack\Entities\BreadcrumbsViewComposer;
use BookStack\Util\DateFormatter;
use BookStack\View\SidebarSectionManager;
use BookStack\View\ViewBlockManager;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\View;
@@ -34,7 +34,7 @@ class ViewTweaksServiceProvider extends ServiceProvider
// View Globals
View::share('dates', $this->app->make(DateFormatter::class));
View::share('sidebar', $this->app->make(SidebarSectionManager::class));
View::share('viewBlocks', $this->app->make(ViewBlockManager::class));
// Custom blade view directives
Blade::directive('icon', function ($expression) {
-139
View File
@@ -1,139 +0,0 @@
<?php
namespace BookStack\View;
use BookStack\View\SidebarSections\BooksIndexActions;
use BookStack\View\SidebarSections\BooksIndexNew;
use BookStack\View\SidebarSections\BooksIndexPopular;
use BookStack\View\SidebarSections\BooksIndexRecents;
use BookStack\View\SidebarSections\BooksShowActions;
use BookStack\View\SidebarSections\BooksShowActivity;
use BookStack\View\SidebarSections\BooksShowDetails;
use BookStack\View\SidebarSections\BooksShowSearchForm;
use BookStack\View\SidebarSections\BooksShowShelves;
use BookStack\View\SidebarSections\BooksShowTags;
use BookStack\View\SidebarSections\ChaptersShowActions;
use BookStack\View\SidebarSections\ChaptersShowBookTree;
use BookStack\View\SidebarSections\ChaptersShowDetails;
use BookStack\View\SidebarSections\ChaptersShowSearchForm;
use BookStack\View\SidebarSections\ChaptersShowTags;
use BookStack\View\SidebarSections\PagesShowActions;
use BookStack\View\SidebarSections\PagesShowAttachments;
use BookStack\View\SidebarSections\PagesShowBookTree;
use BookStack\View\SidebarSections\PagesShowDetails;
use BookStack\View\SidebarSections\PagesShowPageNav;
use BookStack\View\SidebarSections\PagesShowTags;
use BookStack\View\SidebarSections\ShelvesIndexActions;
use BookStack\View\SidebarSections\ShelvesIndexNew;
use BookStack\View\SidebarSections\ShelvesIndexPopular;
use BookStack\View\SidebarSections\ShelvesIndexRecents;
use BookStack\View\SidebarSections\ShelvesShowActions;
use BookStack\View\SidebarSections\ShelvesShowActivity;
use BookStack\View\SidebarSections\ShelvesShowDetails;
use BookStack\View\SidebarSections\ShelvesShowTags;
use Illuminate\Contracts\Container\BindingResolutionException;
class SidebarSectionManager
{
/**
* @var array<string, array<string, class-string<SidebarSectionInterface>[]>>
*/
protected array $sectionByLocation = [
'shelves-index' => [
'left' => [
ShelvesIndexRecents::class,
ShelvesIndexPopular::class,
ShelvesIndexNew::class,
],
'right' => [
ShelvesIndexActions::class,
],
],
'shelves-show' => [
'left' => [
ShelvesShowTags::class,
ShelvesShowDetails::class,
ShelvesShowActivity::class,
],
'right' => [
ShelvesShowActions::class,
],
],
'books-index' => [
'left' => [
BooksIndexRecents::class,
BooksIndexPopular::class,
BooksIndexNew::class,
],
'right' => [
BooksIndexActions::class,
],
],
'books-show' => [
'left' => [
BooksShowSearchForm::class,
BooksShowTags::class,
BooksShowShelves::class,
BooksShowActivity::class,
],
'right' => [
BooksShowDetails::class,
BooksShowActions::class,
],
],
'chapters-show' => [
'left' => [
ChaptersShowSearchForm::class,
ChaptersShowTags::class,
ChaptersShowBookTree::class,
],
'right' => [
ChaptersShowDetails::class,
ChaptersShowActions::class,
],
],
'pages-show' => [
'left' => [
PagesShowTags::class,
PagesShowAttachments::class,
PagesShowPageNav::class,
PagesShowBookTree::class,
],
'right' => [
PagesShowDetails::class,
PagesShowActions::class,
],
],
];
/**
* Register a sidebar section to be displayed at the given location and position.
* @param class-string<SidebarSectionInterface> $sectionClass
*/
public function register(string $location, string $position, string $sectionClass): void
{
if (!isset($this->sectionByLocation[$location])) {
$this->sectionByLocation[$location] = [];
}
if (!isset($this->sectionByLocation[$location][$position])) {
$this->sectionByLocation[$location][$position] = [];
}
$this->sectionByLocation[$location][$position][] = $sectionClass;
}
/**
* Get all sidebar sections registered for a given location.
*
* @return SidebarSectionInterface[]
* @throws BindingResolutionException
*/
public function getSectionsForLocation(string $location, string $position): array
{
$sections = array_unique($this->sectionByLocation[$location][$position] ?? []);
return array_map(function (string $className) {
return app()->make($className);
}, $sections);
}
}
@@ -2,7 +2,7 @@
namespace BookStack\View;
abstract class SidebarSection implements SidebarSectionInterface
abstract class ViewBlock implements ViewBlockInterface
{
protected string $view;
@@ -4,10 +4,10 @@ namespace BookStack\View;
use Illuminate\Http\Request;
interface SidebarSectionInterface
interface ViewBlockInterface
{
/**
* Get the view to render for this section.
* Get the view to render for this block.
*/
public function getView(): string;
+139
View File
@@ -0,0 +1,139 @@
<?php
namespace BookStack\View;
use BookStack\View\ViewBlocks\BooksIndexActions;
use BookStack\View\ViewBlocks\BooksIndexNew;
use BookStack\View\ViewBlocks\BooksIndexPopular;
use BookStack\View\ViewBlocks\BooksIndexRecents;
use BookStack\View\ViewBlocks\BooksShowActions;
use BookStack\View\ViewBlocks\BooksShowActivity;
use BookStack\View\ViewBlocks\BooksShowDetails;
use BookStack\View\ViewBlocks\BooksShowSearchForm;
use BookStack\View\ViewBlocks\BooksShowShelves;
use BookStack\View\ViewBlocks\BooksShowTags;
use BookStack\View\ViewBlocks\ChaptersShowActions;
use BookStack\View\ViewBlocks\ChaptersShowBookTree;
use BookStack\View\ViewBlocks\ChaptersShowDetails;
use BookStack\View\ViewBlocks\ChaptersShowSearchForm;
use BookStack\View\ViewBlocks\ChaptersShowTags;
use BookStack\View\ViewBlocks\PagesShowActions;
use BookStack\View\ViewBlocks\PagesShowAttachments;
use BookStack\View\ViewBlocks\PagesShowBookTree;
use BookStack\View\ViewBlocks\PagesShowDetails;
use BookStack\View\ViewBlocks\PagesShowPageNav;
use BookStack\View\ViewBlocks\PagesShowTags;
use BookStack\View\ViewBlocks\ShelvesIndexActions;
use BookStack\View\ViewBlocks\ShelvesIndexNew;
use BookStack\View\ViewBlocks\ShelvesIndexPopular;
use BookStack\View\ViewBlocks\ShelvesIndexRecents;
use BookStack\View\ViewBlocks\ShelvesShowActions;
use BookStack\View\ViewBlocks\ShelvesShowActivity;
use BookStack\View\ViewBlocks\ShelvesShowDetails;
use BookStack\View\ViewBlocks\ShelvesShowTags;
use Illuminate\Contracts\Container\BindingResolutionException;
class ViewBlockManager
{
/**
* @var array<string, array<string, class-string<ViewBlockInterface>[]>>
*/
protected array $blocksByLocationAndPosition = [
'shelves-index' => [
'left' => [
ShelvesIndexRecents::class,
ShelvesIndexPopular::class,
ShelvesIndexNew::class,
],
'right' => [
ShelvesIndexActions::class,
],
],
'shelves-show' => [
'left' => [
ShelvesShowTags::class,
ShelvesShowDetails::class,
ShelvesShowActivity::class,
],
'right' => [
ShelvesShowActions::class,
],
],
'books-index' => [
'left' => [
BooksIndexRecents::class,
BooksIndexPopular::class,
BooksIndexNew::class,
],
'right' => [
BooksIndexActions::class,
],
],
'books-show' => [
'left' => [
BooksShowSearchForm::class,
BooksShowTags::class,
BooksShowShelves::class,
BooksShowActivity::class,
],
'right' => [
BooksShowDetails::class,
BooksShowActions::class,
],
],
'chapters-show' => [
'left' => [
ChaptersShowSearchForm::class,
ChaptersShowTags::class,
ChaptersShowBookTree::class,
],
'right' => [
ChaptersShowDetails::class,
ChaptersShowActions::class,
],
],
'pages-show' => [
'left' => [
PagesShowTags::class,
PagesShowAttachments::class,
PagesShowPageNav::class,
PagesShowBookTree::class,
],
'right' => [
PagesShowDetails::class,
PagesShowActions::class,
],
],
];
/**
* Register a block type to be displayed at the given location and position.
* @param class-string<ViewBlockInterface> $blockClass
*/
public function register(string $location, string $position, string $blockClass): void
{
if (!isset($this->blocksByLocationAndPosition[$location])) {
$this->blocksByLocationAndPosition[$location] = [];
}
if (!isset($this->blocksByLocationAndPosition[$location][$position])) {
$this->blocksByLocationAndPosition[$location][$position] = [];
}
$this->blocksByLocationAndPosition[$location][$position][] = $blockClass;
}
/**
* Get all blocks registered for a given location and position.
*
* @return ViewBlockInterface[]
* @throws BindingResolutionException
*/
public function getForLocation(string $location, string $position): array
{
$sections = array_unique($this->blocksByLocationAndPosition[$location][$position] ?? []);
return array_map(function (string $className) {
return app()->make($className);
}, $sections);
}
}
@@ -1,11 +1,11 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class BooksIndexActions extends SidebarSection
class BooksIndexActions extends ViewBlock
{
protected string $view = 'books.parts.index-sidebar-section-actions';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Queries\BookQueries;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class BooksIndexNew extends SidebarSection
class BooksIndexNew extends ViewBlock
{
protected string $view = 'books.parts.index-sidebar-section-new';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Queries\BookQueries;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class BooksIndexPopular extends SidebarSection
class BooksIndexPopular extends ViewBlock
{
protected string $view = 'books.parts.index-sidebar-section-popular';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Queries\BookQueries;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class BooksIndexRecents extends SidebarSection
class BooksIndexRecents extends ViewBlock
{
protected string $view = 'books.parts.index-sidebar-section-recents';
@@ -1,13 +1,13 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Activity\Tools\UserEntityWatchOptions;
use BookStack\Entities\Models\Book;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class BooksShowActions extends SidebarSection
class BooksShowActions extends ViewBlock
{
protected string $view = 'books.parts.show-sidebar-section-actions';
@@ -1,13 +1,13 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Activity\ActivityQueries;
use BookStack\Entities\Models\Book;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class BooksShowActivity extends SidebarSection
class BooksShowActivity extends ViewBlock
{
protected string $view = 'books.parts.show-sidebar-section-activity';
@@ -1,14 +1,14 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Activity\Tools\UserEntityWatchOptions;
use BookStack\Entities\Models\Book;
use BookStack\References\ReferenceFetcher;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class BooksShowDetails extends SidebarSection
class BooksShowDetails extends ViewBlock
{
protected string $view = 'books.parts.show-sidebar-section-details';
@@ -1,11 +1,11 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class BooksShowSearchForm extends SidebarSection
class BooksShowSearchForm extends ViewBlock
{
protected string $view = 'entities.search-form';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Models\Book;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class BooksShowShelves extends SidebarSection
class BooksShowShelves extends ViewBlock
{
protected string $view = 'books.parts.show-sidebar-section-shelves';
@@ -1,11 +1,11 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class BooksShowTags extends SidebarSection
class BooksShowTags extends ViewBlock
{
protected string $view = 'books.parts.show-sidebar-section-tags';
@@ -1,13 +1,13 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Activity\Tools\UserEntityWatchOptions;
use BookStack\Entities\Models\Chapter;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ChaptersShowActions extends SidebarSection
class ChaptersShowActions extends ViewBlock
{
protected string $view = 'chapters.parts.show-sidebar-section-actions';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Models\Book;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ChaptersShowBookTree extends SidebarSection
class ChaptersShowBookTree extends ViewBlock
{
protected string $view = 'entities.book-tree';
@@ -1,15 +1,15 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Activity\Tools\UserEntityWatchOptions;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Chapter;
use BookStack\References\ReferenceFetcher;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ChaptersShowDetails extends SidebarSection
class ChaptersShowDetails extends ViewBlock
{
protected string $view = 'chapters.parts.show-sidebar-section-details';
@@ -1,11 +1,11 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ChaptersShowSearchForm extends SidebarSection
class ChaptersShowSearchForm extends ViewBlock
{
protected string $view = 'entities.search-form';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Models\Chapter;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ChaptersShowTags extends SidebarSection
class ChaptersShowTags extends ViewBlock
{
protected string $view = 'chapters.parts.show-sidebar-section-tags';
@@ -1,13 +1,13 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Activity\Tools\UserEntityWatchOptions;
use BookStack\Entities\Models\Page;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class PagesShowActions extends SidebarSection
class PagesShowActions extends ViewBlock
{
protected string $view = 'pages.parts.show-sidebar-section-actions';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Models\Page;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class PagesShowAttachments extends SidebarSection
class PagesShowAttachments extends ViewBlock
{
protected string $view = 'pages.parts.show-sidebar-section-attachments';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Models\Book;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class PagesShowBookTree extends SidebarSection
class PagesShowBookTree extends ViewBlock
{
protected string $view = 'entities.book-tree';
@@ -1,15 +1,15 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Activity\Tools\UserEntityWatchOptions;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Page;
use BookStack\References\ReferenceFetcher;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class PagesShowDetails extends SidebarSection
class PagesShowDetails extends ViewBlock
{
protected string $view = 'pages.parts.show-sidebar-section-details';
@@ -1,13 +1,13 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Tools\PageContent;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class PagesShowPageNav extends SidebarSection
class PagesShowPageNav extends ViewBlock
{
protected string $view = 'pages.parts.show-sidebar-section-page-nav';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Models\Page;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class PagesShowTags extends SidebarSection
class PagesShowTags extends ViewBlock
{
protected string $view = 'pages.parts.show-sidebar-section-tags';
@@ -1,11 +1,11 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ShelvesIndexActions extends SidebarSection
class ShelvesIndexActions extends ViewBlock
{
protected string $view = 'shelves.parts.index-sidebar-section-actions';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Queries\BookshelfQueries;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ShelvesIndexNew extends SidebarSection
class ShelvesIndexNew extends ViewBlock
{
protected string $view = 'shelves.parts.index-sidebar-section-new';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Queries\BookshelfQueries;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ShelvesIndexPopular extends SidebarSection
class ShelvesIndexPopular extends ViewBlock
{
protected string $view = 'shelves.parts.index-sidebar-section-popular';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Queries\BookshelfQueries;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ShelvesIndexRecents extends SidebarSection
class ShelvesIndexRecents extends ViewBlock
{
protected string $view = 'shelves.parts.index-sidebar-section-recents';
@@ -1,12 +1,12 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Models\Bookshelf;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ShelvesShowActions extends SidebarSection
class ShelvesShowActions extends ViewBlock
{
protected string $view = 'shelves.parts.show-sidebar-section-actions';
@@ -1,13 +1,13 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Activity\ActivityQueries;
use BookStack\Entities\Models\Bookshelf;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ShelvesShowActivity extends SidebarSection
class ShelvesShowActivity extends ViewBlock
{
protected string $view = 'shelves.parts.show-sidebar-section-activity';
@@ -1,13 +1,13 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\Entities\Models\Bookshelf;
use BookStack\References\ReferenceFetcher;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ShelvesShowDetails extends SidebarSection
class ShelvesShowDetails extends ViewBlock
{
protected string $view = 'shelves.parts.show-sidebar-section-details';
@@ -1,11 +1,11 @@
<?php
namespace BookStack\View\SidebarSections;
namespace BookStack\View\ViewBlocks;
use BookStack\View\SidebarSection;
use BookStack\View\ViewBlock;
use Illuminate\Http\Request;
class ShelvesShowTags extends SidebarSection
class ShelvesShowTags extends ViewBlock
{
protected string $view = 'shelves.parts.show-sidebar-section-tags';
@@ -6,6 +6,6 @@ $position - string
$sectionVars = get_defined_vars();
$sectionRequest = request();
@endphp
@foreach($sidebar->getSectionsForLocation($location, $position) as $section)
@foreach($viewBlocks->getForLocation($location, $position) as $section)
@include($section->getView(), $section->withData($sectionVars, $sectionRequest))
@endforeach