[COMPONENTS][Collection] Added PrependActorsCollection event [COMPONENTS][Group] Added getGroupCreateForm, used in PrependActorsCollection event to build create a new Group form view

[COMPONENTS][LeftPanel] Removed onEndShowStyles event since the corresponding CSS needed is now consolidated into the default_theme itself [COMPONENTS][RightPanel] Deleted components/RightPanel/RightPanel.php, since its only method (onEndShowStyles) wasn't needed anymore
This commit is contained in:
Eliseu Amaro 2022-01-23 18:56:57 +00:00
parent e4a3438d55
commit bf07fa1ade
No known key found for this signature in database
GPG Key ID: 96DA09D4B97BC2D5
9 changed files with 104 additions and 106 deletions

View File

@ -3,9 +3,14 @@
{% block title %}{{ title }}{% endblock %}
{% block body %}
<div class="frame-section frame-section-padding">
<section class="frame-section frame-section-padding">
<h1 class="frame-section-title">{{ title }}</h1>
{% set prepend_actors_collection = handle_event('PrependActorsCollection', request) %}
{% for widget in prepend_actors_collection %}
{{ widget | raw }}
{% endfor %}
<details class="frame-section section-details-title">
<summary class="details-summary-title">
<strong>
@ -56,5 +61,5 @@
<h2>{{ empty_message }}</h2>
{% endif %}
</section>
</div>
</section>
{% endblock body %}

View File

@ -48,6 +48,7 @@ use Component\Group\Entity\LocalGroup;
use Component\Subscription\Entity\ActorSubscription;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
class Group extends FeedController
@ -130,6 +131,53 @@ class Group extends FeedController
throw new RedirectException('security_login');
}
$create_form = self::getGroupCreateForm($request, $actor);
return [
'_template' => 'group/create.html.twig',
'create_form' => $create_form->createView(),
];
}
/**
* Settings page for the group with the provided nickname, checks if the current actor can administrate given group
*
* @throws ClientException
* @throws NicknameEmptyException
* @throws NicknameInvalidException
* @throws NicknameNotAllowedException
* @throws NicknameTakenException
* @throws NicknameTooLongException
* @throws NoLoggedInUser
* @throws ServerException
*
* @return array
*/
public function groupSettings(Request $request, string $nickname)
{
$local_group = LocalGroup::getByNickname($nickname);
$group_actor = $local_group->getActor();
$actor = Common::actor();
if (!\is_null($group_actor) && $actor->canAdmin($group_actor)) {
return [
'_template' => 'group/settings.html.twig',
'group' => $group_actor,
'personal_info_form' => ActorForms::personalInfo($request, $actor, $local_group)->createView(),
'open_details_query' => $this->string('open'),
];
} else {
throw new ClientException(_m('You do not have permission to edit settings for the group "{group}"', ['{group}' => $nickname]), code: 404);
}
}
/**
* Create a new Group FormInterface getter
*
* @throws RedirectException
* @throws ServerException
*/
public static function getGroupCreateForm(Request $request, E\Actor $actor): FormInterface
{
$create_form = Form::create([
['group_nickname', TextType::class, ['label' => _m('Group nickname')]],
['group_create', SubmitType::class, ['label' => _m('Create this group!')]],
@ -172,41 +220,6 @@ class Group extends FeedController
throw new RedirectException();
}
return [
'_template' => 'group/create.html.twig',
'create_form' => $create_form->createView(),
];
}
/**
* Settings page for the group with the provided nickname, checks if the current actor can administrate given group
*
* @throws ClientException
* @throws NicknameEmptyException
* @throws NicknameInvalidException
* @throws NicknameNotAllowedException
* @throws NicknameTakenException
* @throws NicknameTooLongException
* @throws NoLoggedInUser
* @throws ServerException
*
* @return array
*/
public function groupSettings(Request $request, string $nickname)
{
$local_group = LocalGroup::getByNickname($nickname);
$group_actor = $local_group->getActor();
$actor = Common::actor();
if (!\is_null($group_actor) && $actor->canAdmin($group_actor)) {
return [
'_template' => 'group/settings.html.twig',
'group' => $group_actor,
'personal_info_form' => ActorForms::personalInfo($request, $actor, $local_group)->createView(),
'open_details_query' => $this->string('open'),
];
} else {
throw new ClientException(_m('You do not have permission to edit settings for the group "{group}"', ['{group}' => $nickname]), code: 404);
}
return $create_form;
}
}

View File

@ -0,0 +1,10 @@
<details class="frame-section section-details-title">
<summary class="details-summary-title">
<strong>
{% trans %}Create a group{% endtrans %}
</strong>
</summary>
<form method="GET" class="section-form">
{{ form(create_form) }}
</form>
</details>

View File

@ -67,17 +67,4 @@ class LeftPanel extends Component
return Event::stop;
}
}
/**
* Output our dedicated stylesheet
*
* @param array $styles stylesheets path
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onEndShowStyles(array &$styles, string $route): bool
{
$styles[] = 'components/LeftPanel/assets/css/view.css';
return Event::next;
}
}

View File

@ -1,41 +0,0 @@
<?php
declare(strict_types = 1);
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
namespace Component\RightPanel;
use App\Core\Event;
use App\Core\Modules\Component;
class RightPanel extends Component
{
/**
* Output our dedicated stylesheet
*
* @param array $styles stylesheets path
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onEndShowStyles(array &$styles, string $route): bool
{
$styles[] = 'components/RightPanel/assets/css/view.css';
return Event::next;
}
}

View File

@ -27,6 +27,12 @@ use App\Core\Event;
use App\Core\Modules\Plugin;
use App\Core\Router\RouteLoader;
use App\Core\Router\Router;
use App\Util\Common;
use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException;
use App\Util\Formatting;
use Component\Group\Controller as ComponentGroupController;
use Symfony\Component\HttpFoundation\Request;
class Directory extends Plugin
{
@ -54,4 +60,28 @@ class Directory extends Plugin
$res[] = ['title' => 'Groups', 'path' => Router::url($path_id = 'directory_groups', []), 'path_id' => $path_id];
return Event::next;
}
/**
* Prepend various widgets to Actors Collection template
*
* @param $elements array of widgets to be prepended
*
* @throws RedirectException
* @throws ServerException
*
* @return bool EventHook
*/
public function onPrependActorsCollection(Request $request, array &$elements): bool
{
if (\is_null($actor = Common::actor())) {
return Event::next;
}
if ($request->get('_route') === 'directory_groups') {
$elements[] = Formatting::twigRenderFile('cards/group/create_widget.html.twig', context: [
'create_form' => ComponentGroupController\Group::getGroupCreateForm($request, $actor)->createView(),
]);
}
return Event::next;
}
}

View File

@ -1,3 +1,8 @@
@import url(root.css);
@import url(reset.css);
@import url(widgets/buttons.css);
@import url(widgets/sections.css);
html {
font-family: 'Open Sans', sans-serif;
scroll-margin-top: var(--xxl);

View File

@ -48,10 +48,6 @@ fieldset {
all: unset;
}
section {
all: unset;
}
:link img, :visited img, a img {
border: 0;
}

View File

@ -15,19 +15,12 @@
</title>
{% block stylesheets %}
<link rel='preload' type='text/css' as='style'
href="{{ asset('assets/default_theme/fonts/opensans/opensans.css') }}">
<link rel='preload' type='text/css' as='style' href="{{ asset('assets/default_theme/fonts/opensans/opensans.css') }}">
<link rel='preload' type='text/css' as='style' href="{{ asset('assets/default_theme/fonts/poppins/poppins.css') }}">
<link rel='stylesheet' type='text/css' href="{{ asset('assets/default_theme/fonts/opensans/opensans.css') }}">
<link rel='preload' type='text/css' as='style'
href="{{ asset('assets/default_theme/fonts/poppins/poppins.css') }}">
<link rel='stylesheet' type='text/css' href="{{ asset('assets/default_theme/fonts/poppins/poppins.css') }}">
<link rel='stylesheet' type='text/css' href="{{ asset('assets/default_theme/css/root.css') }}">
<link rel='stylesheet' type='text/css' href="{{ asset('assets/default_theme/css/reset.css') }}">
<link rel='stylesheet' type='text/css' href="{{ asset('assets/default_theme/css/base.css') }}">
<link rel='stylesheet' type='text/css' href="{{ asset('assets/default_theme/css/widgets/buttons.css') }}">
<link rel='stylesheet' type='text/css' href="{{ asset('assets/default_theme/css/widgets/sections.css') }}">
{% for stylesheet in show_stylesheets(app.request.get('_route')) %}
<link rel='preload' type='text/css' as='style' href="{{ preload(asset(stylesheet), { as: 'style' }) }}">