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

NovaeZEditHelpBundle Ibexa4 #137

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@

namespace Novactive\Bundle\NovaeZEditHelpBundle\Command;

use eZ\Publish\API\Repository\Exceptions\ForbiddenException;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
use eZ\Publish\API\Repository\Repository;
use eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroupCreateStruct;
use Ibexa\Contracts\Core\Repository\Exceptions\ForbiddenException;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException;
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeGroupCreateStruct;
use Novactive\Bundle\NovaeZEditHelpBundle\Services\FetchDocumentation;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class CreateContentTypeCommand extends Command
{
/**
* @var Repository
*/
private $repository;
private Repository $repository;

/**
* @required
Expand Down Expand Up @@ -140,9 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$contentTypeDraft->id
)
);
} catch (UnauthorizedException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
} catch (ForbiddenException $e) {
} catch (UnauthorizedException|ForbiddenException $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
}
}
Expand Down
15 changes: 6 additions & 9 deletions components/EditHelpBundle/bundle/Listener/PreContentView.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@

namespace Novactive\Bundle\NovaeZEditHelpBundle\Listener;

use eZ\Publish\Core\MVC\Symfony\Event\PreContentViewEvent;
use EzSystems\EzPlatformContentForms\Content\View\ContentCreateView;
use EzSystems\EzPlatformContentForms\Content\View\ContentEditView;
use Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent;
use Ibexa\ContentForms\Content\View\ContentCreateView;
use Ibexa\ContentForms\Content\View\ContentEditView;
use Novactive\Bundle\NovaeZEditHelpBundle\Services\FetchDocumentation;

class PreContentView
{
protected $fetchDocumentation;

public function __construct(FetchDocumentation $fetchDocumentation)
{
$this->fetchDocumentation = $fetchDocumentation;
}
public function __construct(
protected FetchDocumentation $fetchDocumentation
) { }

public function onPreContentView(PreContentViewEvent $event): void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
edithelp.alert: "This Content Type has an enhanced documentation"
edithelp.help: Help
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
edithelp.alert: "Ce Content Type a une documenation amélioré."
edithelp.alert: "Ce Content Type a une documentation amélioré."
edithelp.help: Aide
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

{% block form_before %}
{{ parent() }}
{% include "@ezdesign/content/edit/tophelp.html.twig" %}
{% include "@ibexadesign/content/edit/tophelp.html.twig" %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,80 +1,84 @@
{#

@var Content documentation
@var Content[] documentation_items (Indexé par l'identifier du field

extend_from_template = "@ibexadesign/content/edit/edit.html.twig"

@admin/content/edit/edit_help.html.twig (templates/themes/admin/content/edit/edit_help.html.twig)
@admin/content/edit/edit.html.twig (@admin/content/edit/edit.html.twig)
@IbexaAdminUi/themes/admin/content/edit_base.html.twig (@IbexaAdminUi/themes/admin/content/edit_base.html.twig)
@IbexaAdminUi/themes/admin/ui/edit_base.html.twig (@IbexaAdminUi/themes/admin/ui/edit_base.html.twig)
@IbexaAdminUi/themes/admin/ui/layout.html.twig (@IbexaAdminUi/themes/admin/ui/layout.html.twig)

#}
{% extends extend_from_template %}

{% trans_default_domain 'content_edit' %}

{% block form_before %}
{{ parent() }}
{% include "@ezdesign/content/edit/tophelp.html.twig" %}
{% include "@ibexadesign/content/edit/tophelp.html.twig" %}
{% endblock %}

{% block form_fields %}
{#
L'idée d'origine c'était de copier le contenu des templates suivants et d'ajouter le bt et la popin...
* vendor/ibexa/admin-ui/src/bundle/Resources/views/themes/admin/content/edit/edit.html.twig
* vendor/ibexa/admin-ui/src/bundle/Resources/views/themes/admin/content/edit_base.html.twig

<section class="container mt-4 px-5 mb-5">
<div class="card ez-card">
<div class="card-body">
Je trouve que ça fait trop d'override de templates critiques

{% for field in form.fieldsData if not field.rendered -%}
{% if field.value is defined %}
{% if items[field.vars.name] is defined %}
Je préfère donc ajouter le bt et la popin après et déplacer le bt avec du js.

<div class="position-absolute" data-toggle="modal" data-target="#modal-{{ field.vars.name }}"
aria-expanded="false" aria-controls="modal-{{ field.vars.name }}">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="20px" height="20px" viewBox="0 0 20 20" version="1.1">
<g>
<path stroke="none" fill-rule="nonzero" fill="rgb(100%,100%,100%)"
fill-opacity="1"
d="M 19.710938 10 C 19.710938 15.363281 15.363281 19.710938 10 19.710938 C 4.636719 19.710938 0.289062 15.363281 0.289062 10 C 0.289062 4.636719 4.636719 0.289062 10 0.289062 C 15.363281 0.289062 19.710938 4.636719 19.710938 10 Z M 19.710938 10 "/>
<path stroke="none" fill-rule="nonzero" fill="rgb(0%,0%,0%)"
fill-opacity="1"
d="M 10 0 C 4.480469 0 0 4.480469 0 10 C 0 15.519531 4.480469 20 10 20 C 15.519531 20 20 15.519531 20 10 C 20 4.480469 15.519531 0 10 0 Z M 10 1.28125 C 14.8125 1.28125 18.71875 5.1875 18.71875 10 C 18.71875 14.8125 14.8125 18.71875 10 18.71875 C 5.1875 18.71875 1.28125 14.8125 1.28125 10 C 1.28125 5.1875 5.1875 1.28125 10 1.28125 Z M 10.148438 3.40625 C 9.601562 3.410156 9.082031 3.480469 8.617188 3.613281 C 8.148438 3.746094 7.707031 3.960938 7.332031 4.234375 C 7.007812 4.46875 6.699219 4.773438 6.460938 5.085938 C 6.046875 5.640625 5.816406 6.253906 5.757812 6.957031 C 5.753906 7.003906 5.75 7.042969 5.75 7.042969 C 5.75 7.046875 7.921875 7.3125 7.929688 7.3125 C 7.9375 7.3125 7.941406 7.289062 7.960938 7.21875 C 8.152344 6.410156 8.507812 5.867188 9.054688 5.539062 C 9.488281 5.277344 10.035156 5.175781 10.632812 5.242188 C 10.90625 5.269531 11.15625 5.335938 11.371094 5.441406 C 11.644531 5.570312 11.890625 5.777344 12.066406 6.023438 C 12.21875 6.238281 12.3125 6.480469 12.339844 6.753906 C 12.347656 6.828125 12.347656 7 12.339844 7.074219 C 12.316406 7.257812 12.269531 7.414062 12.1875 7.570312 C 12.105469 7.730469 12.039062 7.824219 11.910156 7.953125 C 11.710938 8.160156 11.394531 8.4375 10.835938 8.894531 C 10.472656 9.1875 10.230469 9.410156 10.023438 9.628906 C 9.527344 10.144531 9.304688 10.535156 9.164062 11.101562 C 9.074219 11.472656 9.039062 11.855469 9.050781 12.417969 C 9.050781 12.558594 9.054688 12.691406 9.054688 12.714844 L 9.054688 12.757812 L 11.214844 12.757812 L 11.21875 12.519531 C 11.222656 12.191406 11.238281 11.980469 11.273438 11.777344 C 11.332031 11.449219 11.417969 11.277344 11.667969 10.996094 C 11.828125 10.816406 12.039062 10.621094 12.363281 10.351562 C 12.839844 9.949219 13.171875 9.652344 13.488281 9.335938 C 13.980469 8.847656 14.234375 8.511719 14.414062 8.117188 C 14.558594 7.808594 14.636719 7.503906 14.660156 7.164062 C 14.667969 7.085938 14.667969 6.863281 14.660156 6.769531 C 14.617188 6.066406 14.351562 5.445312 13.847656 4.867188 C 13.765625 4.773438 13.570312 4.578125 13.476562 4.492188 C 12.980469 4.054688 12.40625 3.757812 11.71875 3.585938 C 11.300781 3.476562 10.894531 3.425781 10.382812 3.410156 C 10.304688 3.40625 10.226562 3.40625 10.148438 3.40625 Z M 9.054688 13.765625 L 9.054688 15.964844 L 11.257812 15.964844 L 11.257812 13.765625 Z M 9.054688 13.765625 "/>
</g>
</svg>
</div>
Mais pour dépacer ce bt au bon endoit il faut une cible.
Et pour le moment, cette cible, je la crée avec une surchage de edit_macros.html.twig ...
C'est pas terrible...
#}
RemyNovactive marked this conversation as resolved.
Show resolved Hide resolved
{% block form_fields %}
{{ parent() }}

{% for identifier, item in documentation_items %}
{% set button_id = 'nova-help-button--' ~ identifier %}
{% set button_place_id = 'nova-help-button-place--' ~ identifier %}
{% set modal_id = 'nova-help-modal--' ~ identifier %}

{% endif %}
{% if items[field.vars.name] is defined %}
<!-- Modal -->
<div class="modal fade" id="modal-{{ field.vars.name }}" tabindex="-1" role="dialog"
aria-labelledby="modal-{{ field.vars.name }}" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
{% for item, value in items[field.vars.name].fields %}
{% if item != 'identifier' %}
<div class="documentation-item__field {% if item == 'title' %}h4{% endif %}">
{{ ez_render_field(items[field.vars.name], item) }}
</div>
{% endif %}
{% endfor %}
</div>
</div>
</div>
</div>
{% endif %}
<div class="d-flex">
<div class="flex-grow-1 mw-100">
{{- form_widget(field) -}}
</div>
</div>
{% else %}
<div>
{{- form_label(field) -}}
<p class="non-editable">
{{ "content.field.non_editable"|trans|desc('Field type is not editable') }}
</p>
{% do field.setRendered() %}
</div>
{% endif %}
{%- endfor %}
{{ form_widget(form.publish, {'attr': {'hidden': 'hidden'}}) }}
{{ form_widget(form.saveDraft, {'attr': {'hidden': 'hidden'}}) }}
{{ form_widget(form.cancel, {'attr': {'hidden': 'hidden'}}) }}
</div>
</div>
</section>
<button
id="{{ button_id }}"
type="button"
class="btn ibexa-btn js-nova-help-bt"
data-bs-toggle="modal"
data-bs-target="#{{ modal_id }}"
data-identifier="{{ identifier }}"
title="{{ 'edithelp.help'|trans }}"
>
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--trash">
<use xlink:href="{{ ibexa_icon_path('about-info') }}"></use>
</svg>
<span class="ibexa-btn__label">
{{ 'edithelp.help'|trans }}
</span>
</button>

{% endblock %}
{% embed '@ibexadesign/ui/component/modal/modal.html.twig' with {
title: '' ~ identifier,
id: modal_id,
} %}
{% block body_content %}
{% if not ibexa_field_is_empty(item, 'body') %}
{{ ibexa_render_field(item, 'body') }}
{% endif %}
{% if not ibexa_field_is_empty(item, 'image') %}
{{ ibexa_render_field(item, 'image', {
template: '@ibexadesign/fields/simple_ezimage_field.html.twig'
}) }}
{% endif %}
{% endblock %}
{% endembed %}

<script>
var bt=document.getElementById('{{ button_id }}')
var place=document.getElementById('{{ button_place_id }}').nextElementSibling
place.append(bt)
</script>
{% endfor %}
{% endblock %}
Loading
Loading