Skip to content

Commit

Permalink
Merge branch '5.21' into fix/zwsp_in_xliff
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 authored Oct 7, 2024
2 parents d577bc0 + b328bcf commit 6b54c66
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 142 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-5.x.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog 5.x

## 5.21.2 (2024-09-24)
### Bug Fixes
* fix(admin/environment): picker default name value by @Davidmattei in https://github.com/ems-project/elasticms/pull/1020
* fix(admin/wysiwyg): file links in fields (edit and revision view) by @theus77 in https://github.com/ems-project/elasticms/pull/1013

## 5.21.1 (2024-09-19)
### Bug Fixes
* fix(admin/asset-field): asset field remove 'sha1' and '_hash' field by @Davidmattei in https://github.com/ems-project/elasticms/pull/1011
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{%- block jmn_title -%}{%- endblock jmn_title -%}

{%- block jmn_actions -%}
{% set dropDown = 'left' %}
{{ template.block('jmn_button_add', _context)|raw }}
{%- endblock jmn_actions -%}

Expand Down Expand Up @@ -96,7 +97,7 @@
{%- endblock jmn_item_title -%}

{%- block jmn_button_item_edit -%}
<button class="jmn-btn-edit" data-modal-size="md">{{- buttonLabel|default('Edit') -}}</button>
<button class="jmn-btn-edit" data-modal-size="{{- buttonModalSize|default('md') -}}">{{- buttonLabel|default('Edit') -}}</button>
{%- endblock jmn_button_item_edit -%}

{%- block jmn_button_item_delete -%}
Expand All @@ -108,13 +109,13 @@
{%- endblock jmn_button_item_move -%}

{%- block jmn_button_item_view -%}
<button class="jmn-btn-view" data-modal-size="md">{{- buttonLabel|default('View') -}}</button>
<button class="jmn-btn-view" data-modal-size="{{- buttonModalSize|default('md') -}}">{{- buttonLabel|default('View') -}}</button>
{%- endblock jmn_button_item_view -%}

{%- block jmn_button_item_add -%}
<button class="jmn-btn-add" data-add="{{ addNode.id }}" data-modal-size="md">
<button class="jmn-btn-add" data-add="{{ addNode.id }}" data-modal-size="{{- buttonModalSize|default('md') -}}">
{% if addNode.icon %}<i class="{{ addNode.icon }}"></i>{% endif %}
{{- buttonLabel|default("New #{addNode.type}") -}}
{{- buttonLabel|default("New #{addNode.label}") -}}
</button>
{%- endblock jmn_button_item_add -%}

Expand All @@ -140,13 +141,12 @@
{% set node = node|default(config.nodes.root) %}
{% set addNodes = config.nodes.children(node) %}
{% set addMenu = template.block('jmn_button_add_menu', _context)|raw %}

{% if addNodes|length > 0 or addMenu|length > 0 %}
{% if addNodes|length > 0 and addMenu|length > 0 %}
<div class="btn-group btn-group-sm">
<button type="button" class="btn btn-sm btn-default dropdown-toggle jmn-dropdown jmn-dropdown-add" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{- buttonLabel|default('Add') -}}
</button>
<ul class="dropdown-menu pull-right">
<ul class="{{ html_classes('dropdown-menu', { 'pull-right': (dropDown|default('right') == 'right') }) }}">
{{ addMenu|raw }}
</ul>
</div>
Expand All @@ -160,7 +160,7 @@
{%- endblock jmn_button_add_menu -%}

{%- block jmn_modal_title -%}
{% set modalTitle = modalTitle|default("#{action|capitalize} #{node.type|default('')|capitalize}") %}
{% set modalTitle = modalTitle|default("#{action|capitalize} #{node.label|default}") %}
{% if node.icon|default(false) %}<i class="{{ node.icon }}"></i>&nbsp;{% endif %}
{{- modalTitle -}}
{%- endblock jmn_modal_title -%}
Expand All @@ -187,7 +187,7 @@

{%- block jmn_modal_view -%}
{%- if dataFields -%}
{%- import "@EMSAdminUI/bootstrap5/macros/data-field-type.html.twig" as macros -%}
{%- import "@EMSCore/macros/data-field-type.html.twig" as macros -%}
{{ macros.renderDataField(dataFields, rawData, false, [], config.locale) }}
{%- else -%}
<p class="text-red">{{ 'view.data.json-menu-nested-json-preview.field-type-not-found'|trans }}</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
{%- use '@EMSAdminUI/bootstrap5/form/forms.html.twig' -%}
{% trans_default_domain 'EMSCoreBundle' %}

<table id="{{ datatable.id }}" class="table table-condensed table-striped" data-datatable="{{ datatable.frontendOptions|json_encode|e('html_attr') }}">
<thead>
<tr role="row">
{% if datatable.supportsTableActions %}
<th class="fit" data-orderable="false" data-name="_checkbox">
<input type="checkbox" value="" data-grouped-checkbox-target=".{{ (datatable.id ~ '-select')|e('html_attr') }}-to-select">
</th>
{% endif %}
{% for column in datatable.columns %}
<th class="nowrap" data-orderable="{{ column.orderable ? 'true' : 'false' }}" data-name="{{ column.attribute }}">
{% if column.iconClass %}
<i class="{{ column.iconClass }}" aria-hidden="true" title="{{ column.titleKey|trans|e('html_attr') }}"></i>
<span class="sr-only">{{ column.titleKey|trans }}</span>
{% else %}
{{ column.titleKey|trans }}
{% endif %}
</th>
{% endfor %}
{% if datatable.itemActions|length > 0 %}
<th class="nowrap" data-orderable="false">{{ 'key.actions'|trans({}, 'emsco-core') }}</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for line in datatable %}
<tr>
<div class="table-responsive">
<table id="{{ datatable.id }}" class="table table-condensed table-striped" data-datatable="{{ datatable.frontendOptions|json_encode|e('html_attr') }}">
<thead>
<tr role="row">
{% if datatable.supportsTableActions %}
<td class="{{ datatable.attributeName|e('html_attr') }}-to-select">
{{ block('emsco_form_table_column_action_checkbox') }}
</td>
<th class="fit" data-orderable="false" data-name="_checkbox">
<input type="checkbox" value="" data-grouped-checkbox-target=".{{ (datatable.id ~ '-select')|e('html_attr') }}-to-select">
</th>
{% endif %}
{% for column in datatable.columns %}
{{ block(column.tableDataBlock()) }}
<th class="nowrap" data-orderable="{{ column.orderable ? 'true' : 'false' }}" data-name="{{ column.attribute }}">
{% if column.iconClass %}
<i class="{{ column.iconClass }}" aria-hidden="true" title="{{ column.titleKey|trans|e('html_attr') }}"></i>
<span class="sr-only">{{ column.titleKey|trans }}</span>
{% else %}
{{ column.titleKey|trans }}
{% endif %}
</th>
{% endfor %}
{% if datatable.itemActions|length > 0 %}
<td data-search="">
{{ block('emsco_form_table_column_row_actions') }}
</td>
<th class="nowrap" data-orderable="false">{{ 'key.actions'|trans({}, 'emsco-core') }}</th>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>

</thead>
<tbody>
{% for line in datatable %}
<tr>
{% if datatable.supportsTableActions %}
<td class="{{ datatable.attributeName|e('html_attr') }}-to-select">
{{ block('emsco_form_table_column_action_checkbox') }}
</td>
{% endif %}
{% for column in datatable.columns %}
{{ block(column.tableDataBlock()) }}
{% endfor %}
{% if datatable.itemActions|length > 0 %}
<td data-search="">
{{ block('emsco_form_table_column_row_actions') }}
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if datatable.supportsTableActions and datatable.tableMassActions|length > 0%}
<div class="btn-group">
{% for action in datatable.tableMassActions %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,15 +833,15 @@ public function linkDataAction(string $key, ContentTypeService $ctService): Resp
throw new NotFoundHttpException('Impossible to find this item : '.$ouuid);
}

if ('asset' == $category) {
if (\in_array($category, ['asset', 'file'])) {
if (empty($contentType->getAssetField()) && empty($revision->getRawData()[$contentType->getAssetField()])) {
throw new NotFoundHttpException('Asset field not found for '.$revision);
}

return $this->redirectToRoute('file.download', [
'sha1' => $revision->getRawData()[$contentType->getAssetField()]['sha1'],
'type' => $revision->getRawData()[$contentType->getAssetField()]['mimetype'],
'name' => $revision->getRawData()[$contentType->getAssetField()]['filename'],
return $this->redirectToRoute('ems_file_view', [
'sha1' => $revision->getRawData()[$contentType->getAssetField()][EmsFields::CONTENT_FILE_HASH_FIELD_] ?? $revision->getRawData()[$contentType->getAssetField()][EmsFields::CONTENT_FILE_HASH_FIELD],
'type' => $revision->getRawData()[$contentType->getAssetField()][EmsFields::CONTENT_MIME_TYPE_FIELD_] ?? $revision->getRawData()[$contentType->getAssetField()][EmsFields::CONTENT_MIME_TYPE_FIELD],
'name' => $revision->getRawData()[$contentType->getAssetField()][EmsFields::CONTENT_FILE_NAME_FIELD_] ?? $revision->getRawData()[$contentType->getAssetField()][EmsFields::CONTENT_FILE_NAME_FIELD],
]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private function __construct(
private readonly FieldType $fieldType,
public readonly int $id,
public readonly string $type,
public readonly string $label,
public readonly string $role,
public readonly ?string $icon,
public readonly array $deny,
Expand All @@ -33,6 +34,7 @@ public static function fromFieldType(FieldType $fieldType): self
$fieldType,
$fieldType->getId(),
$fieldType->getName(),
$fieldType->getDisplayOption('label', $fieldType->getName()),
$fieldType->getMinimumRole(),
$fieldType->getDisplayOption('icon', null),
$fieldType->getRestrictionOption('json_nested_deny', []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function build(QueryTable $table): void
$table
->setIdField('ouuid')
->setLabelAttribute('label')
->setExtraFrontendOption(['order' => [$this->userService->isSuper() ? 3 : 4, 'desc']])
->setDefaultOrder('modified', 'desc');

$table->addColumn(t('field.label', [], 'emsco-core'), 'label');
Expand Down
19 changes: 17 additions & 2 deletions EMS/core-bundle/src/Form/DataField/WysiwygFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
use EMS\CoreBundle\Entity\FieldType;
use EMS\CoreBundle\Form\Field\AnalyzerPickerType;
use EMS\CoreBundle\Form\Field\WysiwygStylesSetPickerType;
use EMS\CoreBundle\Routes;
use EMS\CoreBundle\Service\ElasticsearchService;
use EMS\CoreBundle\Service\WysiwygStylesSetService;
use EMS\Helpers\Standard\Type;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
Expand Down Expand Up @@ -115,13 +117,20 @@ public function configureOptions(OptionsResolver $resolver): void
public function reverseViewTransform($data, FieldType $fieldType): DataField
{
$path = $this->router->generate('ems_file_view', ['sha1' => '__SHA1__'], UrlGeneratorInterface::ABSOLUTE_PATH);

$out = \preg_replace_callback(
'/('.\preg_quote(\substr($path, 0, \strlen($path) - 8), '/').')([^\n\r"\'\?]*)/i',
fn ($matches) => 'ems://asset:'.$matches[2],
$data
);
if (empty($out)) {

$path = $this->router->generate(Routes::DATA_LINK, ['key' => '__KEY__'], UrlGeneratorInterface::ABSOLUTE_PATH);
$out = \preg_replace_callback(
'/('.\preg_quote(\substr($path, 0, \strlen($path) - 7), '/').')(?P<key>[^\n\r"\'\?]*)/i',
fn ($matches) => 'ems://'.$matches['key'],
$out
);

if ('' === $out) {
$out = null;
}

Expand All @@ -146,6 +155,12 @@ public function viewTransform(DataField $dataField)
fn ($matches) => $path.$matches[2],
$out
);
$path = $this->router->generate(Routes::DATA_LINK, ['key' => '__KEY__'], UrlGeneratorInterface::ABSOLUTE_PATH);
$out = \preg_replace_callback(
'/ems:\/\/(?P<key>file:([^\n\r"\'\?]*))/i',
fn ($matches) => \str_replace('__KEY__', $matches['key'], $path),
Type::string($out)
);

return $out;
}
Expand Down
15 changes: 8 additions & 7 deletions EMS/core-bundle/src/Form/Field/EnvironmentPickerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class EnvironmentPickerType extends ChoiceType
{
/** @var array<mixed> */
private array $choices = [];
private array $environments = [];

public function __construct(private readonly EnvironmentService $service)
{
Expand All @@ -29,7 +29,7 @@ public function getBlockPrefix(): string
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$keys = [];
$choices = [];

if ($options['userPublishEnvironments']) {
$environments = $this->service->getUserPublishEnvironments()->toArray();
Expand All @@ -52,17 +52,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void

foreach ($environments as $env) {
if (($env->getManaged() || !$options['managedOnly']) && !\in_array($env->getName(), $options['ignore'], true)) {
$keys[$env->getName()] = $env;
$this->choices[$env->getName()] = $env;
$choices[$env->getName()] = $env;
$this->environments[$env->getName()] = $env;
}
}
$options['choices'] = $keys;
$options['choices'] = \array_map($options['choice_callback'], $choices);
parent::buildForm($builder, $options);
}

public function configureOptions(OptionsResolver $resolver): void
{
$this->choices = [];
$this->environments = [];
parent::configureOptions($resolver);

$resolver
Expand All @@ -73,7 +73,7 @@ public function configureOptions(OptionsResolver $resolver): void
],
'choice_attr' => function ($category, $key, $index) {
/** @var Environment $dataFieldType */
$dataFieldType = $this->choices[$index];
$dataFieldType = $this->environments[$index];

return [
'data-content' => '<span class="text-'.$dataFieldType->getColor().'"><i class="fa fa-square"></i>&nbsp;&nbsp;'.$dataFieldType->getLabel().'</span>',
Expand All @@ -86,6 +86,7 @@ public function configureOptions(OptionsResolver $resolver): void
'defaultEnvironment' => null,
'ignore' => [],
'choice_translation_domain' => false,
'choice_callback' => fn (Environment $e) => $e->getName(),
])
->setAllowedTypes('defaultEnvironment', ['null', 'bool'])
;
Expand Down
4 changes: 3 additions & 1 deletion EMS/core-bundle/src/Form/Form/ContentTypeFieldsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add(ContentTypeFields::CIRCLES, ContentTypeFieldPickerType::class, $defaultOptions)
->add(ContentTypeFields::BUSINESS_ID, ContentTypeFieldPickerType::class, $defaultOptions)
->add(ContentTypeFields::CATEGORY, ContentTypeFieldPickerType::class, $defaultOptions)
->add(ContentTypeFields::ASSET, ContentTypeFieldPickerType::class, $defaultOptions)
->add(ContentTypeFields::ASSET, ContentTypeFieldPickerType::class, \array_merge($defaultOptions, [
'types' => ['nested'],
]))
;
}

Expand Down
3 changes: 3 additions & 0 deletions EMS/core-bundle/src/Form/Form/ReleaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace EMS\CoreBundle\Form\Form;

use EMS\CoreBundle\Entity\Environment;
use EMS\CoreBundle\Entity\Release;
use EMS\CoreBundle\Form\Field\EnvironmentPickerType;
use EMS\CoreBundle\Form\Field\SubmitEmsType;
Expand Down Expand Up @@ -37,6 +38,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'defaultEnvironment' => false,
'managedOnly' => true,
'label' => t('field.release_environment_target', [], 'emsco-core'),
'choice_callback' => fn (Environment $environment) => $environment,
])
->add('execution_date', DateTimeType::class, [
'required' => false,
Expand All @@ -55,6 +57,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'defaultEnvironment' => true,
'managedOnly' => true,
'label' => t('field.release_environment_source', [], 'emsco-core'),
'choice_callback' => fn (Environment $environment) => $environment,
])
;

Expand Down
Loading

0 comments on commit 6b54c66

Please sign in to comment.