diff --git a/plugins/AttachmentCollections/AttachmentCollections.php b/plugins/AttachmentCollections/AttachmentCollections.php index f890f66ab6..a4cde8f3fa 100644 --- a/plugins/AttachmentCollections/AttachmentCollections.php +++ b/plugins/AttachmentCollections/AttachmentCollections.php @@ -33,7 +33,6 @@ namespace Plugin\AttachmentCollections; use App\Core\DB\DB; use App\Core\Event; -use function App\Core\I18n\_m; use App\Core\Modules\Collection; use App\Core\Router\RouteLoader; use App\Core\Router\Router; @@ -41,10 +40,11 @@ use App\Entity\Actor; use App\Entity\Feed; use App\Entity\LocalUser; use App\Util\Nickname; -use Plugin\AttachmentCollections\Controller as C; +use Plugin\AttachmentCollections\Controller\AttachmentCollections as AttachmentCollectionsController; use Plugin\AttachmentCollections\Entity\AttachmentCollection; use Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry; use Symfony\Component\HttpFoundation\Request; +use function App\Core\I18n\_m; class AttachmentCollections extends Collection { @@ -128,23 +128,23 @@ class AttachmentCollections extends Collection $r->connect( id: 'collections_view_by_actor_id', uri_path: '/actor/{id<\d+>}/collections', - target: [C\Controller::class, 'collectionsViewByActorId'], + target: [AttachmentCollectionsController::class, 'collectionsListViewByActorId'], ); $r->connect( id: 'collections_view_by_nickname', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}/collections', - target: [C\Controller::class, 'collectionsByActorNickname'], + target: [AttachmentCollectionsController::class, 'collectionsListViewByActorNickname'], ); // View notes from a collection by actor id and nickname $r->connect( id: 'collection_notes_view_by_actor_id', uri_path: '/actor/{id<\d+>}/collections/{cid<\d+>}', - target: [C\Controller::class, 'collectionNotesViewByActorId'], + target: [AttachmentCollectionsController::class, 'collectionsEntryViewNotesByActorId'], ); $r->connect( id: 'collection_notes_view_by_nickname', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}/collections/{cid<\d+>}', - target: [C\Controller::class, 'collectionNotesByNickname'], + target: [AttachmentCollectionsController::class, 'collectionsEntryViewNotesByNickname'], ); return Event::next; } diff --git a/plugins/AttachmentCollections/Controller/Controller.php b/plugins/AttachmentCollections/Controller/AttachmentCollections.php similarity index 95% rename from plugins/AttachmentCollections/Controller/Controller.php rename to plugins/AttachmentCollections/Controller/AttachmentCollections.php index bef3c8d870..6844a010a0 100644 --- a/plugins/AttachmentCollections/Controller/Controller.php +++ b/plugins/AttachmentCollections/Controller/AttachmentCollections.php @@ -28,7 +28,7 @@ use App\Core\DB\DB; use App\Core\Router\Router; use Plugin\AttachmentCollections\Entity\AttachmentCollection; -class Controller extends CollectionController +class AttachmentCollections extends CollectionController { public function createCollection(int $owner_id, string $name) { @@ -64,7 +64,7 @@ class Controller extends CollectionController ['cid' => $collection_id], ); return [ - '_template' => 'AttachmentCollections/collection.html.twig', + '_template' => 'AttachmentCollections/collection_entry_view.html.twig', 'attachments' => array_values($attachs), 'bare_notes' => array_values($notes), ]; diff --git a/plugins/AttachmentCollections/templates/AttachmentCollections/collection.html.twig b/plugins/AttachmentCollections/templates/AttachmentCollections/collection_entry_view.html.twig similarity index 91% rename from plugins/AttachmentCollections/templates/AttachmentCollections/collection.html.twig rename to plugins/AttachmentCollections/templates/AttachmentCollections/collection_entry_view.html.twig index acefeb8b90..ba5a29d8e1 100644 --- a/plugins/AttachmentCollections/templates/AttachmentCollections/collection.html.twig +++ b/plugins/AttachmentCollections/templates/AttachmentCollections/collection_entry_view.html.twig @@ -1,4 +1,4 @@ -{% extends 'collections/collection.html.twig' %} +{% extends 'collections/collection_entry_view.html.twig' %} {% block collection_items %} {% for key, attachment in attachments %} diff --git a/src/Core/Controller/CollectionController.php b/src/Core/Controller/CollectionController.php index c8d80b48c5..b7ef980bb3 100644 --- a/src/Core/Controller/CollectionController.php +++ b/src/Core/Controller/CollectionController.php @@ -33,8 +33,6 @@ namespace App\Core\Controller; use App\Core\DB\DB; use App\Core\Form; -use function App\Core\I18n\_m; -use App\Core\Router\Router; use App\Entity\LocalUser; use App\Util\Common; use App\Util\Exception\RedirectException; @@ -42,12 +40,13 @@ use Component\Feed\Util\FeedController; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\HttpFoundation\Request; +use function App\Core\I18n\_m; abstract class CollectionController extends FeedController { - protected string $slug = 'collection'; - protected string $plural_slug = 'collections'; - protected string $page_title = 'collections'; + protected string $slug = 'collectionsEntry'; + protected string $plural_slug = 'collectionsList'; + protected string $page_title = 'Collections'; abstract public function getCollectionUrl(int $owner_id, string $owner_nickname, int $collection_id): string; abstract public function getCollectionItems(int $owner_id, $collection_id): array; @@ -55,15 +54,15 @@ abstract class CollectionController extends FeedController abstract public function getCollectionBy(int $owner_id, int $collection_id); abstract public function createCollection(int $owner_id, string $name); - public function collectionsByActorNickname(Request $request, string $nickname): array + public function collectionsListViewByActorNickname(Request $request, string $nickname): array { $user = DB::findOneBy(LocalUser::class, ['nickname' => $nickname]); - return self::collectionsView($request, $user->getId(), $nickname); + return self::collectionsListView($request, $user->getId(), $nickname); } - public function collectionsViewByActorId(Request $request, int $id): array + public function collectionsListViewByActorId(Request $request, int $id): array { - return self::collectionsView($request, $id, null); + return self::collectionsListView($request, $id, null); } /** @@ -74,16 +73,18 @@ abstract class CollectionController extends FeedController * * @return array twig template options */ - public function collectionsView(Request $request, int $id, ?string $nickname): array + public function collectionsListView(Request $request, int $id, ?string $nickname): array { $collections = $this->getCollectionsBy($id); + $create_title = _m('Create a ' . mb_strtolower(preg_replace( '/([a-z0-9])([A-Z])/', "$1 $2", $this->slug))); + $collections_title = _m('Your ' . mb_strtolower(preg_replace( '/([a-z0-9])([A-Z])/', "$1 $2", $this->plural_slug))); // create collection form $create = null; if (Common::user()?->getId() === $id) { $create = Form::create([ ['name', TextType::class, [ - 'label' => _m('Create ' . $this->slug), + 'label' => $create_title, 'attr' => [ 'placeholder' => _m('Name'), 'required' => 'required', @@ -91,9 +92,9 @@ abstract class CollectionController extends FeedController 'data' => '', ]], ['add_collection', SubmitType::class, [ - 'label' => _m('Create ' . $this->slug), + 'label' => $create_title, 'attr' => [ - 'title' => _m('Create ' . $this->slug), + 'title' => $create_title, ], ]], ]); @@ -190,27 +191,27 @@ abstract class CollectionController extends FeedController }; return [ - '_template' => 'collections/collections.html.twig', + '_template' => 'collections/collection_list_view.html.twig', 'page_title' => $this->page_title, - 'list_title' => 'Your ' . $this->plural_slug, + 'list_title' => $collections_title, 'add_collection' => $create?->createView(), 'fn' => $fn, 'collections' => $collections, ]; } - public function collectionNotesByNickname(Request $request, string $nickname, int $cid): array + public function collectionsEntryViewNotesByNickname(Request $request, string $nickname, int $cid): array { $user = DB::findOneBy(LocalUser::class, ['nickname' => $nickname]); - return self::collectionNotesByActorId($request, $user->getId(), $cid); + return self::collectionsEntryViewNotesByActorId($request, $user->getId(), $cid); } - public function collectionNotesByActorId(Request $request, int $id, int $cid): array + public function collectionsEntryViewNotesByActorId(Request $request, int $id, int $cid): array { $collection = $this->getCollectionBy($id, $cid); $vars = $this->getCollectionItems($id, $cid); return array_merge([ - '_template' => 'collections/collection.html.twig', + '_template' => 'collections/collection_entry_view.html.twig', 'page_title' => $collection->getName(), ], $vars); } diff --git a/templates/collections/collection.html.twig b/templates/collections/collection.html.twig deleted file mode 100644 index bc218848a8..0000000000 --- a/templates/collections/collection.html.twig +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'stdgrid.html.twig' %} -{% import '/cards/note/view.html.twig' as noteView %} - -{% block title %}{{ page_title | trans }}{% endblock %} - -{% block stylesheets %} - {{ parent() }} - -{% endblock stylesheets %} - -{% block body %} -

{{ page_title | trans }}

- {# Backwards compatibility with hAtom 0.1 #} -
-
- {% block collection_items %} - {% endblock collection_items %} -
-
-{% endblock body %} diff --git a/templates/collections/collection_entry_view.html.twig b/templates/collections/collection_entry_view.html.twig new file mode 100644 index 0000000000..3354d1f799 --- /dev/null +++ b/templates/collections/collection_entry_view.html.twig @@ -0,0 +1,11 @@ +{% extends '/feed/feed.html.twig' %} + +{% block title %}{{ page_title | trans }}{% endblock %} + +{% block body %} +
+

{{ page_title | trans }}

+ {% block collection_items %} + {% endblock collection_items %} +
+{% endblock body %} diff --git a/templates/collections/collection_list_view.html.twig b/templates/collections/collection_list_view.html.twig new file mode 100644 index 0000000000..81b4d2d1d8 --- /dev/null +++ b/templates/collections/collection_list_view.html.twig @@ -0,0 +1,34 @@ +{% extends 'stdgrid.html.twig' %} + +{% block title %}{{ page_title | trans }}{% endblock %} + +{% block body %} +
+

{{ page_title | trans }}

+ {% if add_collection %} +
+ {{ form(add_collection) }} +
+ {% endif %} +
+

{{ list_title | trans }}

+ {% for col in collections %} +
+ {{ col.name }} +
+ + {{ icon('edit') | raw }} + + {{ form(fn.editForm(col)) }} +
+
+ + {{ icon('delete') | raw }} + + {{ form(fn.rmForm(col)) }} +
+
+ {% endfor %} +
+
+{% endblock body %} diff --git a/templates/collections/collections.html.twig b/templates/collections/collections.html.twig deleted file mode 100644 index f2d209fc37..0000000000 --- a/templates/collections/collections.html.twig +++ /dev/null @@ -1,43 +0,0 @@ -{% extends 'stdgrid.html.twig' %} -{% import '/cards/note/view.html.twig' as noteView %} - -{% block title %}{{ page_title | trans }}{% endblock %} - -{% block stylesheets %} - {{ parent() }} - -{% endblock stylesheets %} - -{% block body %} -

{{ page_title | trans }}

- {# Backwards compatibility with hAtom 0.1 #} -
-
- {% if add_collection %} -
- {{ form(add_collection) }} -
- {% endif %} -
-

{{ list_title | trans }}

- {% for col in collections %} -
- {{ col.name }} -
- -
{{ icon('edit') | raw }}
-
- {{ form(fn.editForm(col)) }} -
-
- -
{{ icon('delete') | raw }}
-
- {{ form(fn.rmForm(col)) }} -
-
- {% endfor %} -
-
-
-{% endblock body %}