[COMPONENT][Collection] Make MetaCollectionPlugin a trait and abstract collection delete and name update

This commit is contained in:
2022-01-04 21:58:49 +00:00
parent 754135743e
commit 9df9c6a19c
5 changed files with 28 additions and 15 deletions

View File

@@ -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);
}
}

View File

@@ -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();
}

View File

@@ -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);