Skip to content

Commit

Permalink
EZP-29848: Added more flexibility to Versions tab templates
Browse files Browse the repository at this point in the history
  • Loading branch information
webhdx committed Nov 30, 2018
1 parent 9d7ef46 commit 7628ef0
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 91 deletions.
153 changes: 82 additions & 71 deletions src/bundle/Resources/views/content/tab/versions/tab.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,98 @@
{% form_theme form_version_remove_draft '@ezdesign/form_fields.html.twig' %}
{% form_theme form_version_remove_archived '@ezdesign/form_fields.html.twig' %}

{% if draft_pager.currentPageResults is not empty %}
<section>
{{ form_start(form_version_remove_draft, {
'action': path('ezplatform.version.remove'),
'attr': { 'class': 'ez-toggle-btn-state', 'data-toggle-button-id': '#delete-translations-' ~ form_version_remove_draft.remove.vars.id }
}) }}
{% include '@ezdesign/parts/table_header.html.twig' with { headerText: 'tab.versions.draft_under_edit'|trans()|desc('Draft under edit'), tools: tab.table_header_tools(form_version_remove_draft) } %}
{{ include('@ezdesign/content/tab/versions/table.html.twig', {
'versions': draft_pager.currentPageResults,
'is_draft': true,
'form': form_version_remove_draft,
'haveToPaginate': draft_pager.haveToPaginate,
'content_is_user': content_is_user
}) }}
{{ form_end(form_version_remove_draft) }}
{% set table_template_path = table_template_path|default('@ezdesign/content/tab/versions/table.html.twig') %}
{% set show_drafts_table = show_drafts_table|default(draft_pager.currentPageResults is not empty) %}

{% if draft_pager.haveToPaginate %}
<div class="row justify-content-center align-items-center mb-2">
<span class="ez-pagination__text">
{{ 'pagination.viewing'|trans({
'%viewing%': draft_pager.currentPageResults|length,
'%total%': draft_pager.nbResults}, 'pagination')|desc('Viewing <strong>%viewing%</strong> out of <strong>%total%</strong> items')|raw }}
</span>
</div>
<div class="row justify-content-center align-items-center ez-pagination__btn mb-4">
{{ pagerfanta(draft_pager, 'ez',{
'routeName': draft_pagination_params.route_name,
'routeParams': draft_pagination_params.route_params|merge({
'_fragment': constant('EzSystems\\EzPlatformAdminUi\\Tab\\LocationView\\VersionsTab::URI_FRAGMENT'),
}),
'pageParameter': '[page][version_draft]'
{% block tab_content %}
{% block table_wrapper_drafts %}
{% if show_drafts_table %}
<section>
{{ form_start(form_version_remove_draft, {
'action': path('ezplatform.version.remove'),
'attr': { 'class': 'ez-toggle-btn-state', 'data-toggle-button-id': '#delete-translations-' ~ form_version_remove_draft.remove.vars.id }
}) }}
</div>
{% block table_drafts %}
{% include '@ezdesign/parts/table_header.html.twig' with {
'headerText': 'tab.versions.draft_under_edit'|trans()|desc('Draft under edit'),
'tools': tab.table_header_tools(form_version_remove_draft)
} %}
{% include table_template_path with {
'versions': draft_pager.currentPageResults,
'is_draft': true,
'form': form_version_remove_draft,
'haveToPaginate': draft_pager.haveToPaginate,
'content_is_user': content_is_user
} %}

{% if draft_pager.haveToPaginate %}
<div class="row justify-content-center align-items-center mb-2">
<span class="ez-pagination__text">
{{ 'pagination.viewing'|trans({ '%viewing%': draft_pager.currentPageResults|length, '%total%': draft_pager.nbResults }, 'pagination')|desc('Viewing <strong>%viewing%</strong> out of <strong>%total%</strong> items')|raw }}
</span>
</div>
<div class="row justify-content-center align-items-center ez-pagination__btn mb-4">
{{ pagerfanta(draft_pager, 'ez', {
'routeName': draft_pagination_params.route_name,
'routeParams': draft_pagination_params.route_params|merge({
'_fragment': constant('EzSystems\\EzPlatformAdminUi\\Tab\\LocationView\\VersionsTab::URI_FRAGMENT'),
}),
'pageParameter': '[page][version_draft]'
}) }}
</div>
{% endif %}
{% endblock %}
{{ form_end(form_version_remove_draft) }}
</section>
{% include '@ezdesign/content/modal_version_conflict.html.twig' %}
{% endif %}
</section>
{% include '@ezdesign/content/modal_version_conflict.html.twig' %}
{% endif %}
{% endblock %}

{% if published_versions is not empty %}
<section>
{% include '@ezdesign/parts/table_header.html.twig' with { headerText: 'tab.versions.published_version'|trans()|desc('Published version') } %}
{% block table_wrapper_published %}
{% if published_versions is not empty %}
{{ include('@ezdesign/content/tab/versions/table.html.twig', { 'versions': published_versions }) }}
{% else %}
<p>
{{ 'tab.versions.no_permission'|trans()|desc('You don\'t have access to view the content item\'s versions') }}
</p>
<section>
{% block table_published %}
{% include '@ezdesign/parts/table_header.html.twig' with {
'headerText': 'tab.versions.published_version'|trans()|desc('Published version')
} %}
{% include table_template_path with { 'versions': published_versions } %}
{% endblock %}
</section>
{% endif %}
</section>
{% endif %}
{% endblock %}

{% if archived_versions is not empty %}
<section>
{{ form_start(form_version_remove_archived, {
'action': path('ezplatform.version.remove'),
'attr': { 'class': 'ez-toggle-btn-state', 'data-toggle-button-id': '#delete-translations-' ~ form_version_remove_archived.remove.vars.id }
}) }}
{% include '@ezdesign/parts/table_header.html.twig' with { headerText: 'tab.versions.archived_versions'|trans()|desc('Archived versions'), tools: tab.table_header_tools(form_version_remove_archived) } %}
{% block table_wrapper_archived %}
{% if archived_versions is not empty %}
{{ include('@ezdesign/content/tab/versions/table.html.twig', {
'versions': archived_versions,
'form': form_version_remove_archived,
'is_archived': true,
'form_archived_version_restore': form_archived_version_restore,
'content_is_user': content_is_user
}) }}
{% else %}
<p>
{{ 'tab.versions.no_permission'|trans()|desc('You don\'t have access to view the content item\'s versions') }}
</p>
<section>
{{ form_start(form_version_remove_archived, {
'action': path('ezplatform.version.remove'),
'attr': { 'class': 'ez-toggle-btn-state', 'data-toggle-button-id': '#delete-translations-' ~ form_version_remove_archived.remove.vars.id }
}) }}
{% block table_archived %}
{% include '@ezdesign/parts/table_header.html.twig' with {
'headerText': 'tab.versions.archived_versions'|trans()|desc('Archived versions'),
'tools': tab.table_header_tools(form_version_remove_archived)
} %}
{% include table_template_path with {
'versions': archived_versions,
'form': form_version_remove_archived,
'is_archived': true,
'form_archived_version_restore': form_archived_version_restore,
'content_is_user': content_is_user
} %}
{% endblock %}
{{ form_end(form_version_remove_archived) }}
</section>
{% endif %}
{{ form_end(form_version_remove_archived) }}
</section>
{% endif %}

{{ form_start(form_archived_version_restore, {
'action': path('ezplatform.content.edit'),
'attr': { 'class': 'ez-edit-content-form'}
}) }}
{{ form_widget(form_archived_version_restore.language, {'attr': {'hidden': 'hidden'}}) }}
{{ form_end(form_archived_version_restore) }}
{{ form_start(form_archived_version_restore, {
'action': path('ezplatform.content.edit'),
'attr': { 'class': 'ez-edit-content-form'}
}) }}
{{ form_widget(form_archived_version_restore.language, {'attr': {'hidden': 'hidden'}}) }}
{{ form_end(form_archived_version_restore) }}
{% endblock %}
{% endblock %}

{% macro table_header_tools(form) %}
{% set modal_data_target = 'modal-' ~ form.remove.vars.id %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{% endif %}
<th>{{ 'tab.versions.table.version'|trans()|desc('Version') }}</th>
<th>{{ 'tab.versions.table.modified_language'|trans()|desc('Modified language') }}</th>
{% block custom_column_headers %}{% endblock %}
<th>{{ 'tab.versions.table.contributor'|trans()|desc('Contributor') }}</th>
{% if not is_draft_conflict %}
<th>{{ 'tab.versions.table.created'|trans()|desc('Created') }}</th>
Expand Down Expand Up @@ -48,6 +49,7 @@
<td class="ez-table__cell">
{{ admin_ui_config.languages.mappings[version.initialLanguageCode].name }}
</td>
{% block custom_columns %}{% endblock %}
<td class="ez-table__cell">
{% if version.author is not empty %}
{{ ez_content_name(version.author) }}
Expand Down
43 changes: 23 additions & 20 deletions src/lib/Tab/LocationView/VersionsTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
use EzSystems\EzPlatformAdminUi\Form\Data\Version\VersionRemoveData;
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
use EzSystems\EzPlatformAdminUi\Specification\ContentIsUser;
use EzSystems\EzPlatformAdminUi\Tab\AbstractTab;
use EzSystems\EzPlatformAdminUi\Tab\ConditionalTabInterface;
use EzSystems\EzPlatformAdminUi\Tab\EventDispatchingAbstractTab;
use EzSystems\EzPlatformAdminUi\Tab\OrderedTabInterface;
use EzSystems\EzPlatformAdminUi\UI\Dataset\DatasetFactory;
use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Twig\Environment;

class VersionsTab extends AbstractTab implements OrderedTabInterface, ConditionalTabInterface
class VersionsTab extends EventDispatchingAbstractTab implements OrderedTabInterface, ConditionalTabInterface
{
public const FORM_REMOVE_DRAFT = 'version_remove_draft';
public const FORM_REMOVE_ARCHIVED = 'version_remove_archived';
Expand Down Expand Up @@ -55,6 +56,7 @@ class VersionsTab extends AbstractTab implements OrderedTabInterface, Conditiona
* @param \Symfony\Component\Routing\Generator\UrlGeneratorInterface $urlGenerator
* @param \eZ\Publish\API\Repository\PermissionResolver $permissionResolver
* @param \eZ\Publish\API\Repository\UserService $userService
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher
*/
public function __construct(
Environment $twig,
Expand All @@ -63,9 +65,10 @@ public function __construct(
FormFactory $formFactory,
UrlGeneratorInterface $urlGenerator,
PermissionResolver $permissionResolver,
UserService $userService
UserService $userService,
EventDispatcherInterface $eventDispatcher
) {
parent::__construct($twig, $translator);
parent::__construct($twig, $translator, $eventDispatcher);

$this->datasetFactory = $datasetFactory;
$this->formFactory = $formFactory;
Expand Down Expand Up @@ -115,22 +118,24 @@ public function evaluate(array $parameters): bool
}

/**
* @param array $parameters
*
* @return string
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
* {@inheritdoc}
*/
public function getTemplate(): string
{
return '@ezdesign/content/tab/versions/tab.html.twig';
}

/**
* {@inheritdoc}
*/
public function renderView(array $parameters): string
public function getTemplateParameters(array $contextParameters = []): array
{
/** @var \eZ\Publish\API\Repository\Values\Content\Content $content */
$content = $parameters['content'];
$content = $contextParameters['content'];
/** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
$location = $parameters['location'];
$location = $contextParameters['location'];

$draftPaginationParams = $parameters['draft_pagination_params'];
$draftPaginationParams = $contextParameters['draft_pagination_params'];

$versionInfo = $content->getVersionInfo();
$contentInfo = $versionInfo->getContentInfo();
Expand Down Expand Up @@ -164,7 +169,8 @@ public function renderView(array $parameters): string
'archived_version_restore'
);

$viewParameters = [
$parameters = [
'versions_dataset' => $versionsDataset,
'published_versions' => $versionsDataset->getPublishedVersions(),
'archived_versions' => $archivedVersions,
'form_version_remove_draft' => $removeVersionDraftForm->createView(),
Expand All @@ -175,10 +181,7 @@ public function renderView(array $parameters): string
'content_is_user' => (new ContentIsUser($this->userService))->isSatisfiedBy($content),
];

return $this->twig->render(
'@ezdesign/content/tab/versions/tab.html.twig',
array_merge($viewParameters, $parameters)
);
return array_replace($contextParameters, $parameters);
}

/**
Expand Down

0 comments on commit 7628ef0

Please sign in to comment.