mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-10-12 02:01:37 +00:00
Layouts: Updated view block ids/labels to be static
So that their metadata can be read without having to create instances and fullfill dependancy injection just to list. Also added title to interface prefs page.
This commit is contained in:
@@ -165,6 +165,8 @@ class UserAccountController extends Controller
|
||||
*/
|
||||
public function showInterface(ViewBlockManager $viewBlockManager)
|
||||
{
|
||||
$this->setPageTitle(trans('preferences.interface'));
|
||||
|
||||
return view('users.account.interface', [
|
||||
'category' => 'interface',
|
||||
'namedLocations' => $viewBlockManager->getNamedLocations(),
|
||||
|
||||
+13
-13
@@ -4,16 +4,24 @@ namespace BookStack\View;
|
||||
|
||||
abstract class ViewBlock implements ViewBlockInterface
|
||||
{
|
||||
protected string $id;
|
||||
protected string $view;
|
||||
protected string $labelTranslationKey;
|
||||
protected static string $id;
|
||||
protected static string $view;
|
||||
protected static string $labelTranslationKey;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getId(): string
|
||||
public static function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
return static::$id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getLabel(): string
|
||||
{
|
||||
return trans(static::$labelTranslationKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,12 +31,4 @@ abstract class ViewBlock implements ViewBlockInterface
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLabel(): string
|
||||
{
|
||||
return trans($this->labelTranslationKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ interface ViewBlockInterface
|
||||
/**
|
||||
* Get the unique ID for this block.
|
||||
*/
|
||||
public function getId(): string;
|
||||
public static function getId(): string;
|
||||
|
||||
/**
|
||||
* Get the label for this block.
|
||||
*/
|
||||
public function getLabel(): string;
|
||||
public static function getLabel(): string;
|
||||
|
||||
/**
|
||||
* Get the view to render for this block.
|
||||
|
||||
@@ -44,46 +44,49 @@ class ViewBlockManager
|
||||
* @return ViewBlockInterface[]
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
public function getForLocationAndPositionForCurrentUser(string $location, string $position): array
|
||||
public function getInstancesForLocationAndPositionForCurrentUser(string $location, string $position): array
|
||||
{
|
||||
$key = user()->id . ':' . $location;
|
||||
if (isset($this->locationBlockCache[$key])) {
|
||||
return $this->locationBlockCache[$key][$position] ?? [];
|
||||
$blocks = $this->locationBlockCache[$key][$position] ?? [];
|
||||
return $this->blocksToInstances($blocks);
|
||||
}
|
||||
|
||||
$forLocation = $this->getForLocationForCurrentUser($location);
|
||||
$this->locationBlockCache[$key] = $forLocation;
|
||||
|
||||
return $forLocation[$position] ?? [];
|
||||
$blocks = $forLocation[$position] ?? [];
|
||||
return $this->blocksToInstances($blocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instances of the given block classes.
|
||||
* @param class-string<ViewBlockInterface>[] $blocks
|
||||
* @return ViewBlockInterface[]
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
protected function blocksToInstances(array $blocks): array
|
||||
{
|
||||
return array_map(fn (string $blockClass) => app()->make($blockClass), $blocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all blocks registered for a given location, as sets of arrays
|
||||
* keyed by position.
|
||||
* @return array<string, ViewBlockInterface[]>
|
||||
* @throws BindingResolutionException
|
||||
* @return array<string, class-string<ViewBlockInterface>[]>
|
||||
*/
|
||||
public function getForLocation(string $location): array
|
||||
protected function getForLocation(string $location): array
|
||||
{
|
||||
$defaults = ViewBlockDefaults::getForLocation($location) ?? [];
|
||||
$registered = $this->blocksByLocationAndPosition[$location] ?? [];
|
||||
$sections = array_merge_recursive($defaults, $registered);
|
||||
|
||||
$instances = [];
|
||||
foreach ($sections as $position => $blocks) {
|
||||
$instances[$position] = array_map(function (string $className) {
|
||||
return app()->make($className);
|
||||
}, $blocks);
|
||||
}
|
||||
|
||||
return $instances;
|
||||
return array_merge_recursive($defaults, $registered);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all blocks registered for a given location, as sets of arrays
|
||||
* keyed by position, for the current user.
|
||||
* Same as above but with user-specific preferences applied.
|
||||
* @return array<string, ViewBlockInterface[]>
|
||||
* @return array<string, class-string<ViewBlockInterface>[]>
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
public function getForLocationForCurrentUser(string $location): array
|
||||
@@ -160,7 +163,7 @@ class ViewBlockManager
|
||||
|
||||
/**
|
||||
* Convert a blocksByPosition array into a map of block IDs to blocks.
|
||||
* @param array<string, ViewBlockInterface[]> $blocksByPosition
|
||||
* @param array<string, class-string<ViewBlockInterface>[]> $blocksByPosition
|
||||
* @return array<string, ViewBlockInterface>
|
||||
*/
|
||||
protected function blocksByPositionToIdMap(array $blocksByPosition): array
|
||||
@@ -168,7 +171,7 @@ class ViewBlockManager
|
||||
$map = [];
|
||||
foreach ($blocksByPosition as $position => $blocks) {
|
||||
foreach ($blocks as $block) {
|
||||
$map[$block->getId()] = $block;
|
||||
$map[$block::getId()] = $block;
|
||||
}
|
||||
}
|
||||
return $map;
|
||||
@@ -176,7 +179,7 @@ class ViewBlockManager
|
||||
|
||||
/**
|
||||
* Convert a blocksByPosition array into a map of block IDs to their positions.
|
||||
* @param array<string, ViewBlockInterface[]> $blocksByPosition
|
||||
* @param array<string, class-string<ViewBlockInterface>[]> $blocksByPosition
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function blocksByPositionToIdPositionMap(array $blocksByPosition): array
|
||||
@@ -184,7 +187,7 @@ class ViewBlockManager
|
||||
$map = [];
|
||||
foreach ($blocksByPosition as $position => $blocks) {
|
||||
foreach ($blocks as $block) {
|
||||
$map[$block->getId()] = $position;
|
||||
$map[$block::getId()] = $position;
|
||||
}
|
||||
}
|
||||
return $map;
|
||||
|
||||
@@ -15,7 +15,7 @@ class ViewBlockPreferences
|
||||
* 'position-2' => ['block-id-3'],
|
||||
* ]
|
||||
* @param array<string, string[]> $layoutData
|
||||
* @param array<string, ViewBlockInterface[]> $validBlocksByPosition
|
||||
* @param array<string, class-string<ViewBlockInterface>[]> $validBlocksByPosition
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
public function storeByIdPositionMap(
|
||||
@@ -65,7 +65,7 @@ class ViewBlockPreferences
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, ViewBlockInterface[]> $blocksByPosition
|
||||
* @param array<string, class-string<ViewBlockInterface>[]> $blocksByPosition
|
||||
* @return string[]
|
||||
*/
|
||||
protected function extractValidBlockIds(array $blocksByPosition): array
|
||||
@@ -74,7 +74,7 @@ class ViewBlockPreferences
|
||||
|
||||
foreach ($blocksByPosition as $blocks) {
|
||||
foreach ($blocks as $block) {
|
||||
$ids[] = $block->getId();
|
||||
$ids[] = $block::getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class BooksIndexActions extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_books-index-actions';
|
||||
protected string $view = 'books.parts.index-sidebar-section-actions';
|
||||
protected string $labelTranslationKey = 'common.actions';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class BooksIndexNew extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_books-index-new';
|
||||
protected string $view = 'books.parts.index-sidebar-section-new';
|
||||
protected string $labelTranslationKey = 'entities.books_new';
|
||||
protected static string $id = 'builtin_books-index-new';
|
||||
protected static string $view = 'books.parts.index-sidebar-section-new';
|
||||
protected static string $labelTranslationKey = 'entities.books_new';
|
||||
|
||||
public function __construct(
|
||||
protected BookQueries $queries,
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class BooksIndexPopular extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_books-index-popular';
|
||||
protected string $view = 'books.parts.index-sidebar-section-popular';
|
||||
protected string $labelTranslationKey = 'entities.books_popular';
|
||||
protected static string $id = 'builtin_books-index-popular';
|
||||
protected static string $view = 'books.parts.index-sidebar-section-popular';
|
||||
protected static string $labelTranslationKey = 'entities.books_popular';
|
||||
|
||||
public function __construct(
|
||||
protected BookQueries $queries,
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class BooksIndexRecents extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_books-index-recents';
|
||||
protected string $view = 'books.parts.index-sidebar-section-recents';
|
||||
protected string $labelTranslationKey = 'entities.recently_viewed';
|
||||
protected static string $id = 'builtin_books-index-recents';
|
||||
protected static string $view = 'books.parts.index-sidebar-section-recents';
|
||||
protected static string $labelTranslationKey = 'entities.recently_viewed';
|
||||
|
||||
public function __construct(
|
||||
protected BookQueries $queries,
|
||||
|
||||
@@ -9,9 +9,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class BooksShowActions extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_books-show-actions';
|
||||
protected string $view = 'books.parts.show-sidebar-section-actions';
|
||||
protected string $labelTranslationKey = 'common.actions';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -9,9 +9,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class BooksShowActivity extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_books-show-activity';
|
||||
protected string $view = 'books.parts.show-sidebar-section-activity';
|
||||
protected string $labelTranslationKey = 'entities.recent_activity';
|
||||
protected static string $id = 'builtin_books-show-activity';
|
||||
protected static string $view = 'books.parts.show-sidebar-section-activity';
|
||||
protected static string $labelTranslationKey = 'entities.recent_activity';
|
||||
|
||||
public function __construct(
|
||||
protected ActivityQueries $activityQueries,
|
||||
|
||||
@@ -10,9 +10,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class BooksShowDetails extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_books-show-details';
|
||||
protected string $view = 'books.parts.show-sidebar-section-details';
|
||||
protected string $labelTranslationKey = 'common.details';
|
||||
protected static string $id = 'builtin_books-show-details';
|
||||
protected static string $view = 'books.parts.show-sidebar-section-details';
|
||||
protected static string $labelTranslationKey = 'common.details';
|
||||
|
||||
public function __construct(
|
||||
protected ReferenceFetcher $referenceFetcher,
|
||||
|
||||
@@ -7,9 +7,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class BooksShowSearchForm extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_books-show-search-form';
|
||||
protected string $view = 'entities.search-form';
|
||||
protected string $labelTranslationKey = 'common.search';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class BooksShowShelves extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_books-show-shelves';
|
||||
protected string $view = 'books.parts.show-sidebar-section-shelves';
|
||||
protected string $labelTranslationKey = 'entities.shelves';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -7,9 +7,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class BooksShowTags extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_books-show-tags';
|
||||
protected string $view = 'books.parts.show-sidebar-section-tags';
|
||||
protected string $labelTranslationKey = 'entities.tags';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -9,9 +9,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ChaptersShowActions extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_chapters-show-actions';
|
||||
protected string $view = 'chapters.parts.show-sidebar-section-actions';
|
||||
protected string $labelTranslationKey = 'common.actions';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ChaptersShowBookTree extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_chapters-show-book-tree';
|
||||
protected string $view = 'entities.book-tree';
|
||||
protected string $labelTranslationKey = 'entities.books_navigation';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -11,9 +11,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ChaptersShowDetails extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_chapters-show-details';
|
||||
protected string $view = 'chapters.parts.show-sidebar-section-details';
|
||||
protected string $labelTranslationKey = 'common.details';
|
||||
protected static string $id = 'builtin_chapters-show-details';
|
||||
protected static string $view = 'chapters.parts.show-sidebar-section-details';
|
||||
protected static string $labelTranslationKey = 'common.details';
|
||||
|
||||
public function __construct(
|
||||
protected ReferenceFetcher $referenceFetcher,
|
||||
|
||||
@@ -7,9 +7,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ChaptersShowSearchForm extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_chapters-show-search-form';
|
||||
protected string $view = 'entities.search-form';
|
||||
protected string $labelTranslationKey = 'common.search';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ChaptersShowTags extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_chapters-show-tags';
|
||||
protected string $view = 'chapters.parts.show-sidebar-section-tags';
|
||||
protected string $labelTranslationKey = 'entities.tags';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -6,9 +6,9 @@ use BookStack\View\ViewBlock;
|
||||
|
||||
class HomeActions extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_home-actions';
|
||||
protected string $view = 'home.parts.configured-section-actions';
|
||||
protected string $labelTranslationKey = 'common.actions';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -13,12 +13,12 @@ class HomeRecentActivity implements ViewBlockInterface
|
||||
) {
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
public static function getId(): string
|
||||
{
|
||||
return 'builtin_home-recent-activity';
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
public static function getLabel(): string
|
||||
{
|
||||
return trans('entities.recent_activity');
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ class HomeRecentDrafts implements ViewBlockInterface
|
||||
) {
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
public static function getId(): string
|
||||
{
|
||||
return 'builtin_home-recent-drafts';
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
public static function getLabel(): string
|
||||
{
|
||||
return trans('entities.my_recent_drafts');
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ class HomeRecentlyUpdatedPages implements ViewBlockInterface
|
||||
) {
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
public static function getId(): string
|
||||
{
|
||||
return 'builtin_home-recently-updated-pages';
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
public static function getLabel(): string
|
||||
{
|
||||
return trans('entities.recently_updated_pages');
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@ class HomeRecentlyViewedOrRecentBooks implements ViewBlockInterface
|
||||
) {
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
public static function getId(): string
|
||||
{
|
||||
return 'builtin_home-recently-viewed-or-recent-books';
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
public static function getLabel(): string
|
||||
{
|
||||
$key = user()->isGuest() ? 'books_recent' : 'my_recently_viewed';
|
||||
return trans("entities.{$key}");
|
||||
|
||||
@@ -13,12 +13,12 @@ class HomeTopFavourites implements ViewBlockInterface
|
||||
) {
|
||||
}
|
||||
|
||||
public function getId(): string
|
||||
public static function getId(): string
|
||||
{
|
||||
return 'builtin_home-top-favourites';
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
public static function getLabel(): string
|
||||
{
|
||||
return trans('entities.my_most_viewed_favourites');
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class PagesShowActions extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_pages-show-actions';
|
||||
protected string $view = 'pages.parts.show-sidebar-section-actions';
|
||||
protected string $labelTranslationKey = 'common.actions';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class PagesShowAttachments extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_pages-show-attachments';
|
||||
protected string $view = 'pages.parts.show-sidebar-section-attachments';
|
||||
protected string $labelTranslationKey = 'entities.pages_attachments';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class PagesShowBookTree extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_pages-show-book-tree';
|
||||
protected string $view = 'entities.book-tree';
|
||||
protected string $labelTranslationKey = 'entities.books_navigation';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -11,9 +11,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class PagesShowDetails extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_pages-show-details';
|
||||
protected string $view = 'pages.parts.show-sidebar-section-details';
|
||||
protected string $labelTranslationKey = 'common.details';
|
||||
protected static string $id = 'builtin_pages-show-details';
|
||||
protected static string $view = 'pages.parts.show-sidebar-section-details';
|
||||
protected static string $labelTranslationKey = 'common.details';
|
||||
|
||||
public function __construct(
|
||||
protected ReferenceFetcher $referenceFetcher,
|
||||
|
||||
@@ -9,9 +9,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class PagesShowPageNav extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_pages-show-page-nav';
|
||||
protected string $view = 'pages.parts.show-sidebar-section-page-nav';
|
||||
protected string $labelTranslationKey = 'entities.pages_navigation';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class PagesShowTags extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_pages-show-tags';
|
||||
protected string $view = 'pages.parts.show-sidebar-section-tags';
|
||||
protected string $labelTranslationKey = 'entities.tags';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -7,9 +7,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ShelvesIndexActions extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_shelves-index-actions';
|
||||
protected string $view = 'shelves.parts.index-sidebar-section-actions';
|
||||
protected string $labelTranslationKey = 'common.actions';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ShelvesIndexNew extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_shelves-index-new';
|
||||
protected string $view = 'shelves.parts.index-sidebar-section-new';
|
||||
protected string $labelTranslationKey = 'entities.shelves_new';
|
||||
protected static string $id = 'builtin_shelves-index-new';
|
||||
protected static string $view = 'shelves.parts.index-sidebar-section-new';
|
||||
protected static string $labelTranslationKey = 'entities.shelves_new';
|
||||
|
||||
public function __construct(
|
||||
protected BookshelfQueries $queries,
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ShelvesIndexPopular extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_shelves-index-popular';
|
||||
protected string $view = 'shelves.parts.index-sidebar-section-popular';
|
||||
protected string $labelTranslationKey = 'entities.shelves_popular';
|
||||
protected static string $id = 'builtin_shelves-index-popular';
|
||||
protected static string $view = 'shelves.parts.index-sidebar-section-popular';
|
||||
protected static string $labelTranslationKey = 'entities.shelves_popular';
|
||||
|
||||
public function __construct(
|
||||
protected BookshelfQueries $queries,
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ShelvesIndexRecents extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_shelves-index-recents';
|
||||
protected string $view = 'shelves.parts.index-sidebar-section-recents';
|
||||
protected string $labelTranslationKey = 'entities.recently_viewed';
|
||||
protected static string $id = 'builtin_shelves-index-recents';
|
||||
protected static string $view = 'shelves.parts.index-sidebar-section-recents';
|
||||
protected static string $labelTranslationKey = 'entities.recently_viewed';
|
||||
|
||||
public function __construct(
|
||||
protected BookshelfQueries $queries,
|
||||
|
||||
@@ -8,9 +8,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ShelvesShowActions extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_shelves-show-actions';
|
||||
protected string $view = 'shelves.parts.show-sidebar-section-actions';
|
||||
protected string $labelTranslationKey = 'common.actions';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -9,9 +9,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ShelvesShowActivity extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_shelves-show-activity';
|
||||
protected string $view = 'shelves.parts.show-sidebar-section-activity';
|
||||
protected string $labelTranslationKey = 'entities.recent_activity';
|
||||
protected static string $id = 'builtin_shelves-show-activity';
|
||||
protected static string $view = 'shelves.parts.show-sidebar-section-activity';
|
||||
protected static string $labelTranslationKey = 'entities.recent_activity';
|
||||
|
||||
public function __construct(
|
||||
protected ActivityQueries $activityQueries,
|
||||
|
||||
@@ -9,9 +9,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ShelvesShowDetails extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_shelves-show-details';
|
||||
protected string $view = 'shelves.parts.show-sidebar-section-details';
|
||||
protected string $labelTranslationKey = 'common.details';
|
||||
protected static string $id = 'builtin_shelves-show-details';
|
||||
protected static string $view = 'shelves.parts.show-sidebar-section-details';
|
||||
protected static string $labelTranslationKey = 'common.details';
|
||||
|
||||
public function __construct(
|
||||
protected ReferenceFetcher $referenceFetcher,
|
||||
|
||||
@@ -7,9 +7,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class ShelvesShowTags extends ViewBlock
|
||||
{
|
||||
protected string $id = 'builtin_shelves-show-tags';
|
||||
protected string $view = 'shelves.parts.show-sidebar-section-tags';
|
||||
protected string $labelTranslationKey = 'entities.tags';
|
||||
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
|
||||
{
|
||||
|
||||
@@ -5,6 +5,6 @@ $position - string
|
||||
@php
|
||||
$sectionVars = get_defined_vars();
|
||||
@endphp
|
||||
@foreach($viewBlocks->getForLocationAndPositionForCurrentUser($location, $position) as $section)
|
||||
@include($section->getView($sectionVars), $section->withData($sectionVars))
|
||||
@foreach($viewBlocks->getInstancesForLocationAndPositionForCurrentUser($location, $position) as $block)
|
||||
@include($block->getView($sectionVars), $block->withData($sectionVars))
|
||||
@endforeach
|
||||
@@ -1,10 +1,8 @@
|
||||
{{--
|
||||
$block - ViewBlockInterface - View Block instance to show
|
||||
--}}
|
||||
<li data-block-id="{{ $block->getId() }}"
|
||||
@php /** @var $block class-string<\BookStack\View\ViewBlockInterface> */ @endphp
|
||||
<li data-block-id="{{ $block::getId() }}"
|
||||
class="scroll-box-item items-center">
|
||||
<div class="handle px-s">@icon('grip')</div>
|
||||
<div class="text-small">{{ $block->getLabel() }}</div>
|
||||
<div class="text-small">{{ $block::getLabel() }}</div>
|
||||
<div class="buttons flex-container-row items-center ml-auto px-xxs py-xxs">
|
||||
<button type="button" data-action="move_left" class="icon-button p-xxs"
|
||||
title="{{ trans('common.move_left') }}">@icon('chevron-left')</button>
|
||||
|
||||
@@ -22,13 +22,11 @@ class ViewBlockDefaultsTest extends TestCase
|
||||
|
||||
$blocks = array_unique($classes);
|
||||
foreach ($blocks as $block) {
|
||||
$instance = app()->make($block);
|
||||
|
||||
$id = $instance->getId();
|
||||
$id = $block::getId();
|
||||
$this->assertArrayNotHasKey($id, $trueById);
|
||||
$trueById[$id] = true;
|
||||
|
||||
$label = $instance->getLabel();
|
||||
$label = $block::getLabel();
|
||||
$this->assertIsString($label);
|
||||
$this->assertDoesNotMatchRegularExpression('/^[a-z]{1,10}\./', $label);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user