diff --git a/app/Config/cache.php b/app/Config/cache.php index 01c822a65..d897a86db 100644 --- a/app/Config/cache.php +++ b/app/Config/cache.php @@ -1,7 +1,5 @@ */ - public function withData(array $viewData): array; + public function getViewData(array $viewData): array; } diff --git a/app/View/ViewBlocks/BooksIndexActions.php b/app/View/ViewBlocks/BooksIndexActions.php index 83327d63d..47e8c6a79 100644 --- a/app/View/ViewBlocks/BooksIndexActions.php +++ b/app/View/ViewBlocks/BooksIndexActions.php @@ -2,16 +2,15 @@ namespace BookStack\View\ViewBlocks; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class BooksIndexActions extends ViewBlock +class BooksIndexActions extends SimpleViewBlock { protected static string $id = 'builtin_books-index-actions'; protected static string $view = 'books.parts.index-sidebar-section-actions'; protected static string $labelTranslationKey = 'common.actions'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { return [ 'view' => $viewData['view'], diff --git a/app/View/ViewBlocks/BooksIndexNew.php b/app/View/ViewBlocks/BooksIndexNew.php index daab45a46..0006ce4b3 100644 --- a/app/View/ViewBlocks/BooksIndexNew.php +++ b/app/View/ViewBlocks/BooksIndexNew.php @@ -3,10 +3,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Queries\BookQueries; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class BooksIndexNew extends ViewBlock +class BooksIndexNew extends SimpleViewBlock { protected static string $id = 'builtin_books-index-new'; protected static string $view = 'books.parts.index-sidebar-section-new'; @@ -17,7 +16,7 @@ class BooksIndexNew extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { $new = $this->queries->visibleForList() ->orderBy('created_at', 'desc') diff --git a/app/View/ViewBlocks/BooksIndexPopular.php b/app/View/ViewBlocks/BooksIndexPopular.php index bfaee41e8..20dacca96 100644 --- a/app/View/ViewBlocks/BooksIndexPopular.php +++ b/app/View/ViewBlocks/BooksIndexPopular.php @@ -3,10 +3,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Queries\BookQueries; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class BooksIndexPopular extends ViewBlock +class BooksIndexPopular extends SimpleViewBlock { protected static string $id = 'builtin_books-index-popular'; protected static string $view = 'books.parts.index-sidebar-section-popular'; @@ -17,7 +16,7 @@ class BooksIndexPopular extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { return [ 'popular' => $this->queries->popularForList()->take(4)->get(), diff --git a/app/View/ViewBlocks/BooksIndexRecents.php b/app/View/ViewBlocks/BooksIndexRecents.php index 48abeb486..8ed506318 100644 --- a/app/View/ViewBlocks/BooksIndexRecents.php +++ b/app/View/ViewBlocks/BooksIndexRecents.php @@ -3,10 +3,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Queries\BookQueries; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class BooksIndexRecents extends ViewBlock +class BooksIndexRecents extends SimpleViewBlock { protected static string $id = 'builtin_books-index-recents'; protected static string $view = 'books.parts.index-sidebar-section-recents'; @@ -17,7 +16,7 @@ class BooksIndexRecents extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { $recents = null; if (!user()->isGuest()) { diff --git a/app/View/ViewBlocks/BooksShowActions.php b/app/View/ViewBlocks/BooksShowActions.php index c7312f285..a85f12315 100644 --- a/app/View/ViewBlocks/BooksShowActions.php +++ b/app/View/ViewBlocks/BooksShowActions.php @@ -4,16 +4,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Activity\Tools\UserEntityWatchOptions; use BookStack\Entities\Models\Book; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class BooksShowActions extends ViewBlock +class BooksShowActions extends SimpleViewBlock { protected static string $id = 'builtin_books-show-actions'; protected static string $view = 'books.parts.show-sidebar-section-actions'; protected static string $labelTranslationKey = 'common.actions'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Book $book */ $book = $viewData['book']; diff --git a/app/View/ViewBlocks/BooksShowActivity.php b/app/View/ViewBlocks/BooksShowActivity.php index 14943bb8d..e56b6e585 100644 --- a/app/View/ViewBlocks/BooksShowActivity.php +++ b/app/View/ViewBlocks/BooksShowActivity.php @@ -4,10 +4,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Activity\ActivityQueries; use BookStack\Entities\Models\Book; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class BooksShowActivity extends ViewBlock +class BooksShowActivity extends SimpleViewBlock { protected static string $id = 'builtin_books-show-activity'; protected static string $view = 'books.parts.show-sidebar-section-activity'; @@ -18,7 +17,7 @@ class BooksShowActivity extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Book $book */ $book = $viewData['book']; diff --git a/app/View/ViewBlocks/BooksShowDetails.php b/app/View/ViewBlocks/BooksShowDetails.php index 582aec8b9..0409566bf 100644 --- a/app/View/ViewBlocks/BooksShowDetails.php +++ b/app/View/ViewBlocks/BooksShowDetails.php @@ -5,10 +5,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Activity\Tools\UserEntityWatchOptions; use BookStack\Entities\Models\Book; use BookStack\References\ReferenceFetcher; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class BooksShowDetails extends ViewBlock +class BooksShowDetails extends SimpleViewBlock { protected static string $id = 'builtin_books-show-details'; protected static string $view = 'books.parts.show-sidebar-section-details'; @@ -19,7 +18,7 @@ class BooksShowDetails extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Book $book */ $book = $viewData['book']; diff --git a/app/View/ViewBlocks/BooksShowSearchForm.php b/app/View/ViewBlocks/BooksShowSearchForm.php index 2fe099047..bea92898b 100644 --- a/app/View/ViewBlocks/BooksShowSearchForm.php +++ b/app/View/ViewBlocks/BooksShowSearchForm.php @@ -2,16 +2,15 @@ namespace BookStack\View\ViewBlocks; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class BooksShowSearchForm extends ViewBlock +class BooksShowSearchForm extends SimpleViewBlock { protected static string $id = 'builtin_books-show-search-form'; protected static string $view = 'entities.search-form'; protected static string $labelTranslationKey = 'common.search'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { return [ 'label' => trans('entities.books_search_this'), diff --git a/app/View/ViewBlocks/BooksShowShelves.php b/app/View/ViewBlocks/BooksShowShelves.php index 590311c7f..e91ec84da 100644 --- a/app/View/ViewBlocks/BooksShowShelves.php +++ b/app/View/ViewBlocks/BooksShowShelves.php @@ -3,16 +3,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Models\Book; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class BooksShowShelves extends ViewBlock +class BooksShowShelves extends SimpleViewBlock { protected static string $id = 'builtin_books-show-shelves'; protected static string $view = 'books.parts.show-sidebar-section-shelves'; protected static string $labelTranslationKey = 'entities.shelves'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Book $book */ $book = $viewData['book']; diff --git a/app/View/ViewBlocks/BooksShowTags.php b/app/View/ViewBlocks/BooksShowTags.php index 0448cd970..26d13eac2 100644 --- a/app/View/ViewBlocks/BooksShowTags.php +++ b/app/View/ViewBlocks/BooksShowTags.php @@ -2,16 +2,15 @@ namespace BookStack\View\ViewBlocks; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class BooksShowTags extends ViewBlock +class BooksShowTags extends SimpleViewBlock { protected static string $id = 'builtin_books-show-tags'; protected static string $view = 'books.parts.show-sidebar-section-tags'; protected static string $labelTranslationKey = 'entities.tags'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { return [ 'book' => $viewData['book'], diff --git a/app/View/ViewBlocks/ChaptersShowActions.php b/app/View/ViewBlocks/ChaptersShowActions.php index 1beb9c591..af9b5f6da 100644 --- a/app/View/ViewBlocks/ChaptersShowActions.php +++ b/app/View/ViewBlocks/ChaptersShowActions.php @@ -4,16 +4,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Activity\Tools\UserEntityWatchOptions; use BookStack\Entities\Models\Chapter; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ChaptersShowActions extends ViewBlock +class ChaptersShowActions extends SimpleViewBlock { protected static string $id = 'builtin_chapters-show-actions'; protected static string $view = 'chapters.parts.show-sidebar-section-actions'; protected static string $labelTranslationKey = 'common.actions'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Chapter $chapter */ $chapter = $viewData['chapter']; diff --git a/app/View/ViewBlocks/ChaptersShowBookTree.php b/app/View/ViewBlocks/ChaptersShowBookTree.php index 03f36862d..dd8164fb4 100644 --- a/app/View/ViewBlocks/ChaptersShowBookTree.php +++ b/app/View/ViewBlocks/ChaptersShowBookTree.php @@ -3,16 +3,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Models\Book; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ChaptersShowBookTree extends ViewBlock +class ChaptersShowBookTree extends SimpleViewBlock { protected static string $id = 'builtin_chapters-show-book-tree'; protected static string $view = 'entities.book-tree'; protected static string $labelTranslationKey = 'entities.books_navigation'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Book $book */ $book = $viewData['book']; diff --git a/app/View/ViewBlocks/ChaptersShowDetails.php b/app/View/ViewBlocks/ChaptersShowDetails.php index 700b848f4..79750536e 100644 --- a/app/View/ViewBlocks/ChaptersShowDetails.php +++ b/app/View/ViewBlocks/ChaptersShowDetails.php @@ -6,10 +6,9 @@ use BookStack\Activity\Tools\UserEntityWatchOptions; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Chapter; use BookStack\References\ReferenceFetcher; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ChaptersShowDetails extends ViewBlock +class ChaptersShowDetails extends SimpleViewBlock { protected static string $id = 'builtin_chapters-show-details'; protected static string $view = 'chapters.parts.show-sidebar-section-details'; @@ -20,7 +19,7 @@ class ChaptersShowDetails extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Book $book */ $book = $viewData['book']; diff --git a/app/View/ViewBlocks/ChaptersShowSearchForm.php b/app/View/ViewBlocks/ChaptersShowSearchForm.php index 0014e30ea..f7fd87d5d 100644 --- a/app/View/ViewBlocks/ChaptersShowSearchForm.php +++ b/app/View/ViewBlocks/ChaptersShowSearchForm.php @@ -2,16 +2,15 @@ namespace BookStack\View\ViewBlocks; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ChaptersShowSearchForm extends ViewBlock +class ChaptersShowSearchForm extends SimpleViewBlock { protected static string $id = 'builtin_chapters-show-search-form'; protected static string $view = 'entities.search-form'; protected static string $labelTranslationKey = 'common.search'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { return [ 'label' => trans('entities.chapters_search_this'), diff --git a/app/View/ViewBlocks/ChaptersShowTags.php b/app/View/ViewBlocks/ChaptersShowTags.php index e513ee66b..f79e16d7b 100644 --- a/app/View/ViewBlocks/ChaptersShowTags.php +++ b/app/View/ViewBlocks/ChaptersShowTags.php @@ -3,16 +3,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Models\Chapter; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ChaptersShowTags extends ViewBlock +class ChaptersShowTags extends SimpleViewBlock { protected static string $id = 'builtin_chapters-show-tags'; protected static string $view = 'chapters.parts.show-sidebar-section-tags'; protected static string $labelTranslationKey = 'entities.tags'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Chapter $chapter */ $chapter = $viewData['chapter']; diff --git a/app/View/ViewBlocks/HomeActions.php b/app/View/ViewBlocks/HomeActions.php index 211a60df5..02e20a56a 100644 --- a/app/View/ViewBlocks/HomeActions.php +++ b/app/View/ViewBlocks/HomeActions.php @@ -2,15 +2,15 @@ namespace BookStack\View\ViewBlocks; -use BookStack\View\ViewBlock; +use BookStack\View\SimpleViewBlock; -class HomeActions extends ViewBlock +class HomeActions extends SimpleViewBlock { protected static string $id = 'builtin_home-actions'; protected static string $view = 'home.parts.configured-section-actions'; protected static string $labelTranslationKey = 'common.actions'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { return [ 'view' => $viewData['view'] ?? '', diff --git a/app/View/ViewBlocks/HomeRecentActivity.php b/app/View/ViewBlocks/HomeRecentActivity.php index 06869990f..3877a6b51 100644 --- a/app/View/ViewBlocks/HomeRecentActivity.php +++ b/app/View/ViewBlocks/HomeRecentActivity.php @@ -3,10 +3,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Activity\ActivityQueries; -use BookStack\View\ViewBlockInterface; -use Illuminate\Http\Request; +use BookStack\View\BaseViewBlock; -class HomeRecentActivity implements ViewBlockInterface +class HomeRecentActivity extends BaseViewBlock { public function __construct( protected ActivityQueries $activityQueries @@ -32,7 +31,7 @@ class HomeRecentActivity implements ViewBlockInterface return 'home.parts.configured-section-recent-activity'; } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { $activity = $this->activityQueries->latest(10); return [ diff --git a/app/View/ViewBlocks/HomeRecentDrafts.php b/app/View/ViewBlocks/HomeRecentDrafts.php index dc8892513..15dcf0747 100644 --- a/app/View/ViewBlocks/HomeRecentDrafts.php +++ b/app/View/ViewBlocks/HomeRecentDrafts.php @@ -3,9 +3,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Queries\PageQueries; -use BookStack\View\ViewBlockInterface; +use BookStack\View\BaseViewBlock; -class HomeRecentDrafts implements ViewBlockInterface +class HomeRecentDrafts extends BaseViewBlock { public function __construct( protected PageQueries $pageQueries @@ -31,7 +31,7 @@ class HomeRecentDrafts implements ViewBlockInterface return 'home.parts.configured-section-recent-drafts'; } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { $draftPages = []; diff --git a/app/View/ViewBlocks/HomeRecentlyUpdatedPages.php b/app/View/ViewBlocks/HomeRecentlyUpdatedPages.php index 99bec7928..953a96c6a 100644 --- a/app/View/ViewBlocks/HomeRecentlyUpdatedPages.php +++ b/app/View/ViewBlocks/HomeRecentlyUpdatedPages.php @@ -3,10 +3,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Queries\PageQueries; -use BookStack\View\ViewBlockInterface; -use Illuminate\Http\Request; +use BookStack\View\BaseViewBlock; -class HomeRecentlyUpdatedPages implements ViewBlockInterface +class HomeRecentlyUpdatedPages extends BaseViewBlock { public function __construct( protected PageQueries $queries @@ -32,7 +31,7 @@ class HomeRecentlyUpdatedPages implements ViewBlockInterface return 'home.parts.configured-section-recently-updated-pages'; } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { $recentlyUpdatedPages = $this->queries->visibleForList() ->where('draft', false) diff --git a/app/View/ViewBlocks/HomeRecentlyViewedOrRecentBooks.php b/app/View/ViewBlocks/HomeRecentlyViewedOrRecentBooks.php index 64cb897ef..3a75ffd8a 100644 --- a/app/View/ViewBlocks/HomeRecentlyViewedOrRecentBooks.php +++ b/app/View/ViewBlocks/HomeRecentlyViewedOrRecentBooks.php @@ -4,11 +4,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Queries\EntityQueries; use BookStack\Entities\Queries\QueryRecentlyViewed; -use BookStack\Entities\Queries\QueryTopFavourites; -use BookStack\View\ViewBlockInterface; -use Illuminate\Http\Request; +use BookStack\View\BaseViewBlock; -class HomeRecentlyViewedOrRecentBooks implements ViewBlockInterface +class HomeRecentlyViewedOrRecentBooks extends BaseViewBlock { public function __construct( protected EntityQueries $queries, @@ -36,7 +34,7 @@ class HomeRecentlyViewedOrRecentBooks implements ViewBlockInterface return 'home.parts.configured-section-recently-viewed-or-recent-books'; } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { if (user()->isGuest()) { $recents = $this->queries->books->visibleForList() diff --git a/app/View/ViewBlocks/HomeTopFavourites.php b/app/View/ViewBlocks/HomeTopFavourites.php index 28eeed15d..2b8bb3aca 100644 --- a/app/View/ViewBlocks/HomeTopFavourites.php +++ b/app/View/ViewBlocks/HomeTopFavourites.php @@ -3,10 +3,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Queries\QueryTopFavourites; -use BookStack\View\ViewBlockInterface; -use Illuminate\Http\Request; +use BookStack\View\BaseViewBlock; -class HomeTopFavourites implements ViewBlockInterface +class HomeTopFavourites extends BaseViewBlock { public function __construct( protected QueryTopFavourites $topFavourites @@ -32,7 +31,7 @@ class HomeTopFavourites implements ViewBlockInterface return 'home.parts.configured-section-top-favourites'; } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { $favourites = $this->topFavourites->run(6); return [ diff --git a/app/View/ViewBlocks/PagesShowActions.php b/app/View/ViewBlocks/PagesShowActions.php index 06a184fa3..25e99ced8 100644 --- a/app/View/ViewBlocks/PagesShowActions.php +++ b/app/View/ViewBlocks/PagesShowActions.php @@ -4,16 +4,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Activity\Tools\UserEntityWatchOptions; use BookStack\Entities\Models\Page; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class PagesShowActions extends ViewBlock +class PagesShowActions extends SimpleViewBlock { protected static string $id = 'builtin_pages-show-actions'; protected static string $view = 'pages.parts.show-sidebar-section-actions'; protected static string $labelTranslationKey = 'common.actions'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Page $page */ $page = $viewData['page']; diff --git a/app/View/ViewBlocks/PagesShowAttachments.php b/app/View/ViewBlocks/PagesShowAttachments.php index d29e9e9a6..c61b8b8fb 100644 --- a/app/View/ViewBlocks/PagesShowAttachments.php +++ b/app/View/ViewBlocks/PagesShowAttachments.php @@ -3,16 +3,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Models\Page; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class PagesShowAttachments extends ViewBlock +class PagesShowAttachments extends SimpleViewBlock { protected static string $id = 'builtin_pages-show-attachments'; protected static string $view = 'pages.parts.show-sidebar-section-attachments'; protected static string $labelTranslationKey = 'entities.pages_attachments'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Page $page */ $page = $viewData['page']; diff --git a/app/View/ViewBlocks/PagesShowBookTree.php b/app/View/ViewBlocks/PagesShowBookTree.php index 4f5b6af6c..22bed36d0 100644 --- a/app/View/ViewBlocks/PagesShowBookTree.php +++ b/app/View/ViewBlocks/PagesShowBookTree.php @@ -3,16 +3,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Models\Book; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class PagesShowBookTree extends ViewBlock +class PagesShowBookTree extends SimpleViewBlock { protected static string $id = 'builtin_pages-show-book-tree'; protected static string $view = 'entities.book-tree'; protected static string $labelTranslationKey = 'entities.books_navigation'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Book $book */ $book = $viewData['book']; diff --git a/app/View/ViewBlocks/PagesShowDetails.php b/app/View/ViewBlocks/PagesShowDetails.php index 6bbe9a8b2..d2d00e71d 100644 --- a/app/View/ViewBlocks/PagesShowDetails.php +++ b/app/View/ViewBlocks/PagesShowDetails.php @@ -6,10 +6,9 @@ use BookStack\Activity\Tools\UserEntityWatchOptions; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Page; use BookStack\References\ReferenceFetcher; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class PagesShowDetails extends ViewBlock +class PagesShowDetails extends SimpleViewBlock { protected static string $id = 'builtin_pages-show-details'; protected static string $view = 'pages.parts.show-sidebar-section-details'; @@ -20,7 +19,7 @@ class PagesShowDetails extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Book $book */ $book = $viewData['book']; diff --git a/app/View/ViewBlocks/PagesShowPageNav.php b/app/View/ViewBlocks/PagesShowPageNav.php index 2a013ec2f..f76e8e521 100644 --- a/app/View/ViewBlocks/PagesShowPageNav.php +++ b/app/View/ViewBlocks/PagesShowPageNav.php @@ -4,16 +4,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Models\Page; use BookStack\Entities\Tools\PageContent; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class PagesShowPageNav extends ViewBlock +class PagesShowPageNav extends SimpleViewBlock { protected static string $id = 'builtin_pages-show-page-nav'; protected static string $view = 'pages.parts.show-sidebar-section-page-nav'; protected static string $labelTranslationKey = 'entities.pages_navigation'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Page $page */ $page = $viewData['page']; diff --git a/app/View/ViewBlocks/PagesShowTags.php b/app/View/ViewBlocks/PagesShowTags.php index 3edbb3288..f6a9f567f 100644 --- a/app/View/ViewBlocks/PagesShowTags.php +++ b/app/View/ViewBlocks/PagesShowTags.php @@ -3,16 +3,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Models\Page; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class PagesShowTags extends ViewBlock +class PagesShowTags extends SimpleViewBlock { protected static string $id = 'builtin_pages-show-tags'; protected static string $view = 'pages.parts.show-sidebar-section-tags'; protected static string $labelTranslationKey = 'entities.tags'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Page $page */ $page = $viewData['page']; diff --git a/app/View/ViewBlocks/ShelvesIndexActions.php b/app/View/ViewBlocks/ShelvesIndexActions.php index 8cd0f47d3..d816f44cb 100644 --- a/app/View/ViewBlocks/ShelvesIndexActions.php +++ b/app/View/ViewBlocks/ShelvesIndexActions.php @@ -2,16 +2,15 @@ namespace BookStack\View\ViewBlocks; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ShelvesIndexActions extends ViewBlock +class ShelvesIndexActions extends SimpleViewBlock { protected static string $id = 'builtin_shelves-index-actions'; protected static string $view = 'shelves.parts.index-sidebar-section-actions'; protected static string $labelTranslationKey = 'common.actions'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { return [ 'view' => $viewData['view'], diff --git a/app/View/ViewBlocks/ShelvesIndexNew.php b/app/View/ViewBlocks/ShelvesIndexNew.php index 21f21a4cf..f3dd3a610 100644 --- a/app/View/ViewBlocks/ShelvesIndexNew.php +++ b/app/View/ViewBlocks/ShelvesIndexNew.php @@ -3,10 +3,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Queries\BookshelfQueries; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ShelvesIndexNew extends ViewBlock +class ShelvesIndexNew extends SimpleViewBlock { protected static string $id = 'builtin_shelves-index-new'; protected static string $view = 'shelves.parts.index-sidebar-section-new'; @@ -17,7 +16,7 @@ class ShelvesIndexNew extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { $new = $this->queries->visibleForList() ->orderBy('created_at', 'desc') diff --git a/app/View/ViewBlocks/ShelvesIndexPopular.php b/app/View/ViewBlocks/ShelvesIndexPopular.php index df62f7c59..071ec7ddb 100644 --- a/app/View/ViewBlocks/ShelvesIndexPopular.php +++ b/app/View/ViewBlocks/ShelvesIndexPopular.php @@ -3,10 +3,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Queries\BookshelfQueries; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ShelvesIndexPopular extends ViewBlock +class ShelvesIndexPopular extends SimpleViewBlock { protected static string $id = 'builtin_shelves-index-popular'; protected static string $view = 'shelves.parts.index-sidebar-section-popular'; @@ -17,7 +16,7 @@ class ShelvesIndexPopular extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { return [ 'popular' => $this->queries->popularForList()->take(4)->get(), diff --git a/app/View/ViewBlocks/ShelvesIndexRecents.php b/app/View/ViewBlocks/ShelvesIndexRecents.php index 5f42d395c..76ed3b91f 100644 --- a/app/View/ViewBlocks/ShelvesIndexRecents.php +++ b/app/View/ViewBlocks/ShelvesIndexRecents.php @@ -3,10 +3,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Queries\BookshelfQueries; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ShelvesIndexRecents extends ViewBlock +class ShelvesIndexRecents extends SimpleViewBlock { protected static string $id = 'builtin_shelves-index-recents'; protected static string $view = 'shelves.parts.index-sidebar-section-recents'; @@ -17,7 +16,7 @@ class ShelvesIndexRecents extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { $recents = null; if (!user()->isGuest()) { diff --git a/app/View/ViewBlocks/ShelvesShowActions.php b/app/View/ViewBlocks/ShelvesShowActions.php index 08a3cdee1..981ed2957 100644 --- a/app/View/ViewBlocks/ShelvesShowActions.php +++ b/app/View/ViewBlocks/ShelvesShowActions.php @@ -3,16 +3,15 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Models\Bookshelf; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ShelvesShowActions extends ViewBlock +class ShelvesShowActions extends SimpleViewBlock { protected static string $id = 'builtin_shelves-show-actions'; protected static string $view = 'shelves.parts.show-sidebar-section-actions'; protected static string $labelTranslationKey = 'common.actions'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Bookshelf $shelf */ $shelf = $viewData['shelf']; diff --git a/app/View/ViewBlocks/ShelvesShowActivity.php b/app/View/ViewBlocks/ShelvesShowActivity.php index a14dbed5f..a51460587 100644 --- a/app/View/ViewBlocks/ShelvesShowActivity.php +++ b/app/View/ViewBlocks/ShelvesShowActivity.php @@ -4,10 +4,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Activity\ActivityQueries; use BookStack\Entities\Models\Bookshelf; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ShelvesShowActivity extends ViewBlock +class ShelvesShowActivity extends SimpleViewBlock { protected static string $id = 'builtin_shelves-show-activity'; protected static string $view = 'shelves.parts.show-sidebar-section-activity'; @@ -18,7 +17,7 @@ class ShelvesShowActivity extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Bookshelf $shelf */ $shelf = $viewData['shelf']; diff --git a/app/View/ViewBlocks/ShelvesShowDetails.php b/app/View/ViewBlocks/ShelvesShowDetails.php index 1ceb21b6f..4d61ac770 100644 --- a/app/View/ViewBlocks/ShelvesShowDetails.php +++ b/app/View/ViewBlocks/ShelvesShowDetails.php @@ -4,10 +4,9 @@ namespace BookStack\View\ViewBlocks; use BookStack\Entities\Models\Bookshelf; use BookStack\References\ReferenceFetcher; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ShelvesShowDetails extends ViewBlock +class ShelvesShowDetails extends SimpleViewBlock { protected static string $id = 'builtin_shelves-show-details'; protected static string $view = 'shelves.parts.show-sidebar-section-details'; @@ -18,7 +17,7 @@ class ShelvesShowDetails extends ViewBlock ) { } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { /** @var Bookshelf $shelf */ $shelf = $viewData['shelf']; diff --git a/app/View/ViewBlocks/ShelvesShowTags.php b/app/View/ViewBlocks/ShelvesShowTags.php index b7af4a738..df6f1025a 100644 --- a/app/View/ViewBlocks/ShelvesShowTags.php +++ b/app/View/ViewBlocks/ShelvesShowTags.php @@ -2,16 +2,15 @@ namespace BookStack\View\ViewBlocks; -use BookStack\View\ViewBlock; -use Illuminate\Http\Request; +use BookStack\View\SimpleViewBlock; -class ShelvesShowTags extends ViewBlock +class ShelvesShowTags extends SimpleViewBlock { protected static string $id = 'builtin_shelves-show-tags'; protected static string $view = 'shelves.parts.show-sidebar-section-tags'; protected static string $labelTranslationKey = 'entities.tags'; - public function withData(array $viewData): array + public function getViewData(array $viewData): array { return [ 'shelf' => $viewData['shelf'], diff --git a/dev/docs/logical-theme-system.md b/dev/docs/logical-theme-system.md index 7093bc00b..8f6e56566 100644 --- a/dev/docs/logical-theme-system.md +++ b/dev/docs/logical-theme-system.md @@ -203,14 +203,16 @@ or the cards shown on the home view. As an example of using this system, we'll define a custom view block which will show on the default home view to state how many books there are in the system. -To start, we'll need to create a custom class to represent our view block. This must implement `\BookStack\View\ViewBlockInterface`: +To start, we'll need to create a custom class to represent our view block. +This must implement `\BookStack\View\ViewBlockInterface`, but we'd advise extending `\BookStack\View\BaseViewBlock` since this will +be used as a core reference implementation, and is intended to be forward compatible with future changes: ```php use BookStack\Entities\Queries\BookQueries; -use BookStack\View\ViewBlockInterface; +use BookStack\View\BaseViewBlock; use BookStack\View\ViewBlockManager; -class BookTotalBlock implements ViewBlockInterface { +class BookTotalBlock extends BaseViewBlock { public function __construct( protected BookQueries $bookQueries @@ -224,15 +226,15 @@ class BookTotalBlock implements ViewBlockInterface { public static function getLabel(): string { - return 'Total books displays'; + return 'Total books display'; } public function getView(array $viewData): string { - return 'blocks.total-blocks'; + return 'blocks.total-books'; } - public function withData(array $viewData): array + public function getViewData(array $viewData): array { $totalBooks = $this->bookQueries->visibleForList()->count(); return [ @@ -248,13 +250,14 @@ The interface has a few required methods: - The `getLabel` method must provide a general string label for the block. - The `getView` method provides a string path to a view file (Can be one custom registered). - This is provided the available view data at time of render, so it can be dynamic based on context. -- The `withData` method is called when block is being rendered, and it should return an array of data which will be merged with existing view data. - - This is also provided available view data, for use as context. +- The `getViewData` method is called when the block is being rendered, and it should return an array of data which will be merged with existing view data. + - This is also provided with the available view data, for use as context. In this example, we're also making use of the `BookQueries` internal BookStack class. -You're able to inject any other dependent classes/services via the constructor like this, and BookStack will attempt to auto-resolve them. +You're able to inject any other dependent classes/services via the constructor like this, and BookStack will attempt to auto-resolve them. +_Keep in mind that any used internal BookStack services or classes are not assured to be stable, so may receive breaking changes on update._ -We can then register this block class using the logical theme system like so: +We can then register our custom block class using the logical theme system like so: ```php use BookStack\Facades\Theme; @@ -271,14 +274,14 @@ Theme::listen(ThemeEvents::VIEW_BLOCKS_REGISTER, function (ViewBlockManager $man ``` The above registration code would typically be within your `functions.php` theme file. -You could also define the above block class in the same file or separate it into its own file +You could also define the above block class in the same file, or separate it into its own class file and include it from the `functions.php` via a `require_once()` call. Lastly, we'll need to create the view for the registered block. -In our example we return `blocks.total-blocks` from the `getView` method, so our view needs to be located at -`blocks/total-blocks.blade.php` from a view providing directory. -In a theme folder, we can just create it at `blocks/total-blocks.blade.php` within the folder path. -If we were building in a module, we'd need to create this at `views/blocks/total-blocks.blade.php` within our module folder. +In our example we return `blocks.total-books` from the `getView` method, so our view needs to be located at +`blocks/total-books.blade.php` from a view providing directory. +In a theme folder, we can just create it at `blocks/total-books.blade.php` within the folder path. +If we were building in a module, we'd need to create this at `views/blocks/total-books.blade.php` within our module folder. For our example, we'll use this content to make use of the data we're passing to the view: ```html @@ -294,4 +297,4 @@ For our example, we'll use this content to make use of the data we're passing to This will then show up on the default home grid view, in the right column. The exact position within that location may change depending on user preferences, but the block will be limited -to the location provided during registration unless it has also been registered for other locations. +to the layout location provided during registration unless it has also been registered for other locations. diff --git a/resources/views/common/view-blocks.blade.php b/resources/views/common/view-blocks.blade.php index 7d26e38b4..98fafbb37 100644 --- a/resources/views/common/view-blocks.blade.php +++ b/resources/views/common/view-blocks.blade.php @@ -6,5 +6,5 @@ $position - string $sectionVars = get_defined_vars(); @endphp @foreach($viewBlocks->getInstancesForLocationAndPositionForCurrentUser($location, $position) as $block) - @include($block->getView($sectionVars), $block->withData($sectionVars)) + @include($block->getView($sectionVars), $block->getViewData($sectionVars)) @endforeach \ No newline at end of file