Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-28521: Design improvements for Content Type Groups list #178

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 68 additions & 7 deletions src/bundle/Controller/ContentTypeGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
use eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup;
use EzSystems\EzPlatformAdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupDeleteData;
use EzSystems\EzPlatformAdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupsDeleteData;
use EzSystems\EzPlatformAdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupUpdateData;
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
use EzSystems\EzPlatformAdminUi\Form\SubmitHandler;
use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use eZ\Publish\API\Repository\Exceptions\InvalidArgumentException;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
use Symfony\Component\Translation\Exception\InvalidArgumentException as TranslationInvalidArgumentException;
use Symfony\Component\Translation\TranslatorInterface;

class ContentTypeGroupController extends Controller
Expand Down Expand Up @@ -71,16 +77,13 @@ public function listAction(): Response
{
$contentTypeGroupList = $this->contentTypeService->loadContentTypeGroups();

$deleteFormsByContentTypeGroupId = [];
foreach ($contentTypeGroupList as $contentTypeGroup) {
$deleteFormsByContentTypeGroupId[$contentTypeGroup->id] = $this->formFactory->deleteContentTypeGroup(
new ContentTypeGroupDeleteData($contentTypeGroup)
)->createView();
}
$deleteContentTypeGroupsForm = $this->formFactory->deleteContentTypeGroups(
new ContentTypeGroupsDeleteData($this->getContentTypeGroupsNumbers($contentTypeGroupList))
);

return $this->render('@EzPlatformAdminUi/admin/content_type_group/list.html.twig', [
'content_type_groups' => $contentTypeGroupList,
'delete_forms' => $deleteFormsByContentTypeGroupId,
'form_content_type_groups_delete' => $deleteContentTypeGroupsForm->createView(),
]);
}

Expand Down Expand Up @@ -192,10 +195,68 @@ public function deleteAction(Request $request, ContentTypeGroup $group): Respons
return $this->redirect($this->generateUrl('ezplatform.content_type_group.list'));
}

/**
* Handles removing content type groups based on submitted form.
*
* @param Request $request
*
* @return Response
*
* @throws TranslationInvalidArgumentException
* @throws InvalidOptionsException
* @throws UnauthorizedException
* @throws InvalidArgumentException
* @throws NotFoundException
* @throws \InvalidArgumentException
*/
public function bulkDeleteAction(Request $request): Response
{
$form = $this->formFactory->deleteContentTypeGroups(
new ContentTypeGroupsDeleteData()
);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$result = $this->submitHandler->handle($form, function (ContentTypeGroupsDeleteData $data) {
foreach ($data->getContentTypeGroups() as $contentTypeGroupId => $selected) {
$group = $this->contentTypeService->loadContentTypeGroup($contentTypeGroupId);
$this->contentTypeService->deleteContentTypeGroup($group);

$this->notificationHandler->success(
$this->translator->trans(
/** @Desc("Content type group '%name%' deleted.") */
'content_type_group.delete.success',
['%name%' => $group->identifier],
'content_type'
)
);
}
});

if ($result instanceof Response) {
return $result;
}
}

return $this->redirect($this->generateUrl('ezplatform.content_type_group.list'));
}

public function viewAction(ContentTypeGroup $group): Response
{
return $this->render('@EzPlatformAdminUi/admin/content_type_group/view.html.twig', [
'content_type_group' => $group,
]);
}

/**
* @param ContentTypeGroup[] $contentTypeGroups
*
* @return array
*/
private function getContentTypeGroupsNumbers(array $contentTypeGroups): array
{
$contentTypeGroupsNumbers = array_column($contentTypeGroups, 'id');

return array_combine($contentTypeGroupsNumbers, array_fill_keys($contentTypeGroupsNumbers, false));
}
}
6 changes: 6 additions & 0 deletions src/bundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ ezplatform.content_type_group.delete:
requirements:
contentTypeGroupId: \d+

ezplatform.content_type_group.bulk_delete:
path: /contenttypegroup/bulk-delete
methods: ['POST']
defaults:
_controller: 'EzPlatformAdminUiBundle:ContentTypeGroup:bulkDelete'

#
# Trash
#
Expand Down
5 changes: 5 additions & 0 deletions src/bundle/Resources/translations/forms.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<target state="new">Remove translation</target>
<note>key: content_translation_remove_form.remove</note>
</trans-unit>
<trans-unit id="4c29e9392116163c51f0e3d4d0c08ff96717f695" resname="content_type_groups_delete_form.delete">
<source>Delete content type groups</source>
<target state="new">Delete content type groups</target>
<note>key: content_type_groups_delete_form.delete</note>
</trans-unit>
<trans-unit id="0ad9197dcdbe88b1a05f099c564dc2b5634f8aa5" resname="ezplatform.language.create.enabled">
<source>Enabled</source>
<target state="new">Enabled</target>
Expand Down
49 changes: 36 additions & 13 deletions src/bundle/Resources/views/admin/content_type_group/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,31 @@
<div class="ez-table-header">
<div class="ez-table-header__headline">{{ 'content_type_group.view.list.title'|trans|desc('Content Type Groups') }}</div>
<div>
<a href="{{ path('ezplatform.content_type_group.create') }}" class="btn btn-primary">
{{ 'content_type_group.view.list.action.add'|trans|desc('Create a Content Type Group') }}
<a title="{{ 'content_type_group.view.list.action.add'|trans|desc('Create a Content Type Group') }}"
href="{{ path('ezplatform.content_type_group.create') }}"
class="btn btn-primary">
<svg class="ez-icon ez-icon-create">
<use xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#create"></use>
</svg>
</a>
<button id="delete-content-type-groups" class="btn btn-danger btn--trigger" disabled data-click="#content_type_groups_delete_delete">
<svg class="ez-icon ez-icon-trash">
<use xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash"></use>
</svg>
</button>
</div>
</div>

{{ form_start(form_content_type_groups_delete, {
'action': path('ezplatform.content_type_group.bulk_delete'),
'attr': { 'class': 'ez-toggle-btn-state', 'data-toggle-button-id': '#delete-content-type-groups' }
}) }}
<table class="table">
<thead>
<tr>
<th></th>
<th>{{ 'content_type_group.view.list.column.identifier'|trans|desc('Name') }}</th>
<th>{{ 'content_type_group.view.list.column.id'|trans|desc('ID') }}</th>
<th></th>
Expand All @@ -40,6 +56,9 @@
<tbody>
{% for content_type_group in content_type_groups %}
<tr>
<td class="ez-checkbox-cell">
{{ form_widget(form_content_type_groups_delete.content_type_groups[content_type_group.id]) }}
</td>
<td>
{% set view_url = path('ezplatform.content_type_group.view', {
contentTypeGroupId: content_type_group.id
Expand All @@ -53,22 +72,26 @@
contentTypeGroupId: content_type_group.id
}) %}

{% set delete_form = delete_forms[content_type_group.id] %}
{{ form_start(delete_form, {
'action': path('ezplatform.content_type_group.delete', { contentTypeGroupId: content_type_group.id })
}) }}

<a href="{{ edit_url }}" class="btn btn-secondary">
{{ 'content_type_group.view.list.action.edit'|trans|desc('Edit') }}
<a title="{{ 'content_type_group.view.list.action.edit'|trans|desc('Edit') }}"
href="{{ edit_url }}"
class="btn btn-icon mx-3">
<svg class="ez-icon ez-icon-edit">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#edit"></use>
</svg>
</a>
{{ form_widget(delete_form.delete, {
'attr': { 'class': 'btn btn-danger' }
}) }}
{{ form_end(delete_form) }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{{ form_end(form_content_type_groups_delete) }}
</section>
{% endblock %}

{% block javascripts %}
{% javascripts
'@EzPlatformAdminUiBundle/Resources/public/js/scripts/button.state.toggle.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
44 changes: 44 additions & 0 deletions src/lib/Form/Data/ContentTypeGroup/ContentTypeGroupsDeleteData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUi\Form\Data\ContentTypeGroup;

use eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup;

/**
* @todo Add validation
*/
class ContentTypeGroupsDeleteData
{
/** @var ContentTypeGroup[]|null */
protected $contentTypeGroups;

/**
* @param ContentTypeGroup[]|null $contentTypeGroups
*/
public function __construct(array $contentTypeGroups = [])
{
$this->contentTypeGroups = $contentTypeGroups;
}

/**
* @return array|null
*/
public function getContentTypeGroups(): ?array
{
return $this->contentTypeGroups;
}

/**
* @param array|null $contentTypeGroups
*/
public function setContentTypeGroups(?array $contentTypeGroups)
{
$this->contentTypeGroups = $contentTypeGroups;
}
}
19 changes: 19 additions & 0 deletions src/lib/Form/Factory/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use EzSystems\EzPlatformAdminUi\Form\Data\Content\Translation\TranslationRemoveData;
use EzSystems\EzPlatformAdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupDeleteData;
use EzSystems\EzPlatformAdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupsDeleteData;
use EzSystems\EzPlatformAdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupUpdateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Language\LanguageCreateData;
use EzSystems\EzPlatformAdminUi\Form\Data\Language\LanguageDeleteData;
Expand Down Expand Up @@ -57,6 +58,7 @@
use EzSystems\EzPlatformAdminUi\Form\Type\Content\Translation\TranslationRemoveType;
use EzSystems\EzPlatformAdminUi\Form\Type\ContentTypeGroup\ContentTypeGroupCreateType;
use EzSystems\EzPlatformAdminUi\Form\Type\ContentTypeGroup\ContentTypeGroupDeleteType;
use EzSystems\EzPlatformAdminUi\Form\Type\ContentTypeGroup\ContentTypeGroupsDeleteType;
use EzSystems\EzPlatformAdminUi\Form\Type\ContentTypeGroup\ContentTypeGroupUpdateType;
use EzSystems\EzPlatformAdminUi\Form\Type\Language\LanguageCreateType;
use EzSystems\EzPlatformAdminUi\Form\Type\Language\LanguageDeleteType;
Expand Down Expand Up @@ -205,6 +207,23 @@ public function deleteContentTypeGroup(
return $this->formFactory->createNamed($name, ContentTypeGroupDeleteType::class, $data);
}

/**
* @param ContentTypeGroupsDeleteData|null $data
* @param null|string $name
*
* @return FormInterface
*
* @throws InvalidOptionsException
*/
public function deleteContentTypeGroups(
ContentTypeGroupsDeleteData $data = null,
?string $name = null
): FormInterface {
$name = $name ?: StringUtil::fqcnToBlockPrefix(ContentTypeGroupsDeleteType::class);

return $this->formFactory->createNamed($name, ContentTypeGroupsDeleteType::class, $data);
}

/**
* @param TranslationAddData|null $data
* @param null|string $name
Expand Down
44 changes: 44 additions & 0 deletions src/lib/Form/Type/ContentTypeGroup/ContentTypeGroupsDeleteType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUi\Form\Type\ContentTypeGroup;

use EzSystems\EzPlatformAdminUi\Form\Data\ContentTypeGroup\ContentTypeGroupsDeleteData;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ContentTypeGroupsDeleteType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('content_type_groups', CollectionType::class, [
'entry_type' => CheckboxType::class,
'required' => false,
'allow_add' => true,
'label' => false,
'entry_options' => ['label' => false],
])
->add('delete', SubmitType::class, [
'attr' => ['hidden' => true],
'label' => /** @Desc("Delete content type groups") */ 'content_type_groups_delete_form.delete',
]);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => ContentTypeGroupsDeleteData::class,
'translation_domain' => 'forms',
]);
}
}