diff --git a/components/Collection/Util/Controller/Collection.php b/components/Collection/Util/Controller/Collection.php index 3ab7bf7514..df32726f8d 100644 --- a/components/Collection/Util/Controller/Collection.php +++ b/components/Collection/Util/Controller/Collection.php @@ -11,10 +11,10 @@ use Component\Feed\Feed; class Collection extends Controller { - public function query(string $query, ?string $language = null, ?Actor $actor = null) + public function query(string $query, ?string $locale = null, ?Actor $actor = null) { - $actor ??= Common::actor(); - $language ??= $actor->getTopLanguage()->getLocale(); - return Feed::query($query, $this->int('page') ?? 1, $language, $actor); + $actor ??= Common::actor(); + $locale ??= Common::currentLanguage()->getLocale(); + return Feed::query($query, $this->int('page') ?? 1, $locale, $actor); } } diff --git a/components/Collection/Util/Controller/MetaCollectionController.php b/components/Collection/Util/Controller/MetaCollectionController.php index cef540c275..4d8cc092fd 100644 --- a/components/Collection/Util/Controller/MetaCollectionController.php +++ b/components/Collection/Util/Controller/MetaCollectionController.php @@ -77,7 +77,7 @@ abstract class MetaCollectionController extends FeedController $collections = $this->getCollectionsByActorId($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))); + $collections_title = _m('The ' . mb_strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1 $2', $this->plural_slug))); // create collection form $create = null; if (Common::user()?->getId() === $id) { @@ -127,7 +127,7 @@ abstract class MetaCollectionController extends FeedController $this->parent = $parent; $this->slug = $slug; } - // there's already a injected function called path, + // there's already an injected function called path, // that maps to Router::url(name, args), but since // I want to preserve nicknames, I think it's better // to use that getUrl function @@ -159,8 +159,7 @@ abstract class MetaCollectionController extends FeedController ]); $edit->handleRequest($this->request); if ($edit->isSubmitted() && $edit->isValid()) { - $collection->setName($edit->getData()['name']); - DB::persist($collection); + $this->parent->setCollectionName($this->id, $this->nick, $collection, $edit->getData()['name']); DB::flush(); throw new RedirectException(); } @@ -181,7 +180,7 @@ abstract class MetaCollectionController extends FeedController ]); $rm->handleRequest($this->request); if ($rm->isSubmitted()) { - DB::remove($collection); + $this->parent->removeCollection($this->id, $this->nick, $collection); DB::flush(); throw new RedirectException(); } diff --git a/components/Collection/Util/MetaCollectionPlugin.php b/components/Collection/Util/MetaCollectionTrait.php similarity index 97% rename from components/Collection/Util/MetaCollectionPlugin.php rename to components/Collection/Util/MetaCollectionTrait.php index 2445d1aab3..9563dec731 100644 --- a/components/Collection/Util/MetaCollectionPlugin.php +++ b/components/Collection/Util/MetaCollectionTrait.php @@ -35,7 +35,6 @@ use App\Core\DB\DB; use App\Core\Event; use App\Core\Form; use function App\Core\I18n\_m; -use App\Core\Modules\Plugin; use App\Entity\Actor; use App\Util\Common; use App\Util\Exception\RedirectException; @@ -45,10 +44,10 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\HttpFoundation\Request; -abstract class MetaCollectionPlugin extends Plugin +trait MetaCollectionTrait { - protected string $slug = 'collection'; - protected string $plural_slug = 'collections'; + //protected string $slug = 'collection'; + //protected string $plural_slug = 'collections'; abstract protected function createCollection(Actor $owner, array $vars, string $name); abstract protected function removeItems(Actor $owner, array $vars, $items, array $collections); diff --git a/plugins/AttachmentCollections/AttachmentCollections.php b/plugins/AttachmentCollections/AttachmentCollections.php index 0ae1b53b3e..05e6394559 100644 --- a/plugins/AttachmentCollections/AttachmentCollections.php +++ b/plugins/AttachmentCollections/AttachmentCollections.php @@ -34,20 +34,24 @@ namespace Plugin\AttachmentCollections; use App\Core\DB\DB; use App\Core\Event; use function App\Core\I18n\_m; +use App\Core\Modules\Plugin; use App\Core\Router\RouteLoader; use App\Core\Router\Router; use App\Entity\Actor; use App\Entity\Feed; use App\Entity\LocalUser; use App\Util\Nickname; -use Component\Collection\Util\MetaCollectionPlugin; +use Component\Collection\Util\MetaCollectionTrait; use Plugin\AttachmentCollections\Controller\AttachmentCollections as AttachmentCollectionsController; use Plugin\AttachmentCollections\Entity\AttachmentCollection; use Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry; use Symfony\Component\HttpFoundation\Request; -class AttachmentCollections extends MetaCollectionPlugin +class AttachmentCollections extends Plugin { + use MetaCollectionTrait; + protected string $slug = 'collection'; + protected string $plural_slug = 'collections'; protected function createCollection(Actor $owner, array $vars, string $name) { $col = AttachmentCollection::create([ diff --git a/plugins/AttachmentCollections/Controller/AttachmentCollections.php b/plugins/AttachmentCollections/Controller/AttachmentCollections.php index 9f86081c0c..1fb33a64c5 100644 --- a/plugins/AttachmentCollections/Controller/AttachmentCollections.php +++ b/plugins/AttachmentCollections/Controller/AttachmentCollections.php @@ -77,4 +77,15 @@ class AttachmentCollections extends MetaCollectionController { return DB::findOneBy(AttachmentCollection::class, ['id' => $collection_id]); } + + public function setCollectionName(int $actor_id, string $actor_nickname, AttachmentCollection $collection, string $name) + { + $collection->setName($name); + DB::persist($collection); + } + + public function removeCollection(int $actor_id, string $actor_nickname, AttachmentCollection $collection) + { + DB::remove($collection); + } }