-
Notifications
You must be signed in to change notification settings - Fork 56
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-29848: Make existing AdminUI tabs extendable by allowing template path and parameters change #728
EZP-29848: Make existing AdminUI tabs extendable by allowing template path and parameters change #728
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review note - this |
||
{{ 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 %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?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\Tab; | ||
|
||
use EzSystems\EzPlatformAdminUi\Tab\Event\TabViewRenderEvent; | ||
use EzSystems\EzPlatformAdminUi\Tab\Event\TabEvents; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
use Twig\Environment; | ||
|
||
/** | ||
* Base class representing Tab using EventDisaptcher for extensibility. | ||
* | ||
* It extends AbstractTab by adding Event Dispatching before rendering view. | ||
*/ | ||
abstract class AbstractEventDispatchingTab extends AbstractTab | ||
{ | ||
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ | ||
protected $eventDispatcher; | ||
|
||
/** | ||
* @param \Twig\Environment $twig | ||
* @param \Symfony\Component\Translation\TranslatorInterface $translator | ||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher | ||
*/ | ||
public function __construct( | ||
Environment $twig, | ||
TranslatorInterface $translator, | ||
EventDispatcherInterface $eventDispatcher | ||
) { | ||
parent::__construct($twig, $translator); | ||
|
||
$this->eventDispatcher = $eventDispatcher; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function renderView(array $parameters): string | ||
{ | ||
$event = new TabViewRenderEvent( | ||
$this->getIdentifier(), | ||
$this->getTemplate(), | ||
$this->getTemplateParameters($parameters) | ||
); | ||
$this->eventDispatcher->dispatch(TabEvents::TAB_RENDER, $event); | ||
|
||
return $this->twig->render( | ||
$event->getTemplate(), | ||
$event->getParameters() | ||
); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
abstract public function getTemplate(): string; | ||
|
||
/** | ||
* @param mixed[] $contextParameters | ||
* | ||
* @return mixed[] | ||
*/ | ||
abstract public function getTemplateParameters(array $contextParameters = []): array; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,11 @@ class TabEvents | |
* Happens just before rendering tab. | ||
*/ | ||
const TAB_PRE_RENDER = 'ezplatform.tab.pre_render'; | ||
|
||
/** | ||
* Is dispatched on tabs extending AbstractEventDispatchingTab. | ||
* | ||
* Allows to manipulate template path and parameters before rendering by Twig. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we allow changing the identifier than the comment should be changed. |
||
*/ | ||
const TAB_RENDER = 'ezplatform.tab.render'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?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\Tab\Event; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
class TabViewRenderEvent extends Event | ||
{ | ||
/** @var string */ | ||
private $tabIdentifier; | ||
|
||
/** @var string */ | ||
private $template; | ||
|
||
/** @var array */ | ||
private $parameters; | ||
|
||
/** | ||
* @param string $tabIdentifier | ||
* @param string $template | ||
* @param array $parameters | ||
*/ | ||
public function __construct(string $tabIdentifier, string $template, array $parameters = []) | ||
{ | ||
$this->tabIdentifier = $tabIdentifier; | ||
$this->template = $template; | ||
$this->parameters = $parameters; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTabIdentifier(): string | ||
{ | ||
return $this->tabIdentifier; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTemplate(): string | ||
{ | ||
return $this->template; | ||
} | ||
|
||
/** | ||
* @param string $template | ||
*/ | ||
public function setTemplate(string $template): void | ||
{ | ||
$this->template = $template; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getParameters(): array | ||
{ | ||
return $this->parameters; | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
*/ | ||
public function setParameters(array $parameters): void | ||
{ | ||
$this->parameters = $parameters; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review note: Same as below.