{{ trans('entities.references') }}
+{{ trans('entities.references_to_desc') }}
+ + @if(count($references) > 0) +{{ trans('entities.references_none') }}
+ @endif + +diff --git a/app/Http/Controllers/ReferenceController.php b/app/Http/Controllers/ReferenceController.php new file mode 100644 index 000000000..bed2c5f30 --- /dev/null +++ b/app/Http/Controllers/ReferenceController.php @@ -0,0 +1,47 @@ +permissions = $permissions; + } + + /** + * Display the references to a given page. + */ + public function page(string $bookSlug, string $pageSlug) + { + /** @var Page $page */ + $page = Page::visible()->whereSlugs($bookSlug, $pageSlug)->firstOrFail(); + + $baseQuery = $page->referencesTo() + ->where('from_type', '=', (new Page())->getMorphClass()) + ->with([ + 'from' => fn(Relation $query) => $query->select(Page::$listAttributes), + 'from.book' => fn(Relation $query) => $query->scopes('visible'), + 'from.chapter' => fn(Relation $query) => $query->scopes('visible') + ]); + + $references = $this->permissions->restrictEntityRelationQuery( + $baseQuery, + 'references', + 'from_id', + 'from_type' + )->get(); + + return view('pages.references', [ + 'page' => $page, + 'references' => $references, + ]); + } +} diff --git a/resources/icons/popular.svg b/resources/icons/popular.svg index ba1f918a5..2ac44f151 100644 --- a/resources/icons/popular.svg +++ b/resources/icons/popular.svg @@ -1,4 +1,3 @@ \ No newline at end of file diff --git a/resources/icons/reference.svg b/resources/icons/reference.svg new file mode 100644 index 000000000..560ec5f37 --- /dev/null +++ b/resources/icons/reference.svg @@ -0,0 +1,3 @@ + diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index db1e8027b..a92b465b8 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -369,4 +369,9 @@ return [ 'convert_to_book_desc' => 'You can convert this chapter to a new book with the same contents. Any permissions set on this chapter will be copied to the new book but any inherited permissions, from the parent book, will not be copied which could lead to a change of access control.', 'convert_chapter' => 'Convert Chapter', 'convert_chapter_confirm' => 'Are you sure you want to convert this chapter?', + + // References + 'references' => 'References', + 'references_none' => 'There are no tracked references to this item.', + 'references_to_desc' => 'Shown below are all the known pages in the system that link to this item.', ]; diff --git a/resources/views/pages/references.blade.php b/resources/views/pages/references.blade.php new file mode 100644 index 000000000..3f35a1629 --- /dev/null +++ b/resources/views/pages/references.blade.php @@ -0,0 +1,34 @@ +@extends('layouts.simple') + +@section('body') + +
{{ trans('entities.references_to_desc') }}
+ + @if(count($references) > 0) +{{ trans('entities.references_none') }}
+ @endif + +