mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
chill_document_edit_button: create new twig extension
This commit is contained in:
parent
53e03395f2
commit
2af3de4f61
@ -38,6 +38,7 @@ class ChillDocStoreExtension extends Extension implements PrependExtensionInterf
|
||||
$loader->load('services/menu.yaml');
|
||||
$loader->load('services/fixtures.yaml');
|
||||
$loader->load('services/form.yaml');
|
||||
$loader->load('services/templating.yaml');
|
||||
}
|
||||
|
||||
public function prepend(ContainerBuilder $container)
|
||||
|
@ -11,13 +11,13 @@
|
||||
{% block js %}
|
||||
{{ parent() }}
|
||||
{{ encore_entry_script_tags('mod_async_upload') }}
|
||||
{{ encore_entry_script_tags('mod_docgen_picktemplate') }}
|
||||
{{ encore_entry_script_tags('mod_docgen_picktemplate') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
{{ parent() }}
|
||||
{{ encore_entry_link_tags('mod_async_upload') }}
|
||||
{{ encore_entry_link_tags('mod_docgen_picktemplate') }}
|
||||
{{ encore_entry_link_tags('mod_docgen_picktemplate') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@ -68,7 +68,7 @@
|
||||
<div data-docgen-template-picker="data-docgen-template-picker" data-entity-class="Chill\PersonBundle\Entity\AccompanyingPeriod" data-entity-id="{{ accompanyingCourse.id }}"></div>
|
||||
|
||||
{% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE', accompanyingCourse) %}
|
||||
<ul class="record_actions">
|
||||
<ul class="record_actions sticky-form-buttons">
|
||||
<li class="create">
|
||||
<a href="{{ path('accompanying_course_document_new', {'course': accompanyingCourse.id}) }}" class="btn btn-create">
|
||||
{{ 'Create'|trans }}
|
||||
|
@ -13,6 +13,7 @@
|
||||
{{ parent() }}
|
||||
{{ encore_entry_link_tags('mod_async_upload') }}
|
||||
{{ encore_entry_link_tags('mod_entity_workflow_pick') }}
|
||||
{{ encore_entry_link_tags('mod_wopi_link') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@ -49,6 +50,9 @@
|
||||
<li>
|
||||
{{ m.download_button(document.object, document.title) }}
|
||||
</li>
|
||||
{% if chill_document_is_editable(document.object) %}
|
||||
<li>{{ document.object|chill_document_edit_button }}</li>
|
||||
{% endif %}
|
||||
{% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_UPDATE', document) %}
|
||||
<li>
|
||||
<a href="{{ path('accompanying_course_document_edit', {'id': document.id, 'course': accompanyingCourse.id}) }}" class="btn btn-edit">
|
||||
@ -74,4 +78,5 @@
|
||||
{{ parent() }}
|
||||
{{ encore_entry_script_tags('mod_async_upload') }}
|
||||
{{ encore_entry_script_tags('mod_entity_workflow_pick') }}
|
||||
{{ encore_entry_script_tags('mod_wopi_link') }}
|
||||
{% endblock %}
|
@ -0,0 +1,15 @@
|
||||
{% set button = {
|
||||
'changeIcon': 'fa-unlock',
|
||||
} %}{#
|
||||
'changeClass': 'btn-update'
|
||||
'noText': false
|
||||
data-doc-title="{{ document.title|e('html_attr') }}"
|
||||
{{ dump() }}
|
||||
|
||||
#}
|
||||
<span data-module="wopi-link"
|
||||
data-wopi-url="{{ path('chill_wopi_file_edit', {'fileId': document.uuid}) }}"
|
||||
data-doc-title="coucou"
|
||||
data-doc-type="{{ document.type|e('html_attr') }}"
|
||||
data-button="{{ button|json_encode }}"
|
||||
></span>
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocStoreBundle\Templating;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class WopiEditTwigExtension extends AbstractExtension
|
||||
{
|
||||
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
new TwigFilter('chill_document_edit_button', [WopiEditTwigExtensionRuntime::class, 'renderEditButton'], [
|
||||
'needs_environment' => true,
|
||||
'is_safe' => ['html'],
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('chill_document_is_editable', [$this, 'isEditable']),
|
||||
];
|
||||
}
|
||||
|
||||
public function isEditable(StoredObject $document): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocStoreBundle\Templating;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\RuntimeExtensionInterface;
|
||||
|
||||
class WopiEditTwigExtensionRuntime implements RuntimeExtensionInterface
|
||||
{
|
||||
|
||||
public const TEMPLATE = '@ChillDocStore/Button/wopi_edit_document.html.twig';
|
||||
|
||||
public function renderEditButton(Environment $environment, StoredObject $document): string
|
||||
{
|
||||
return $environment->render(self::TEMPLATE, [
|
||||
'document' => $document
|
||||
]);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
services:
|
||||
|
||||
Chill\DocStoreBundle\Templating\WopiEditTwigExtension:
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
|
||||
Chill\DocStoreBundle\Templating\WopiEditTwigExtensionRuntime:
|
||||
tags:
|
||||
- { name: twig.runtime }
|
Loading…
x
Reference in New Issue
Block a user