Skip to content

Commit

Permalink
Merge branch '5.x' into fear/asset_label_field
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 authored Oct 25, 2024
2 parents 6e285a9 + 915cc60 commit 4c79092
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@
{% if revision.hasVersionTags %}
<strong><i class="fa fa-tags margin-r-5"></i> Version</strong>
<p class="text-muted">
{% if newVersionTag|default(false) %}<span class="label label-success">New version {{ newVersionTag }}</span>{% endif %}
{% if newVersionTag is not null and newVersionTag != 'silent' %}
<span class="label label-success">New version {{ newVersionTag }}</span>
{% endif %}
{{ revision.versionTag|default('') }}
</p>
<hr/>
Expand Down Expand Up @@ -219,7 +221,7 @@

{% block revisionBody %}
<div class="box revision-view">
{% if revision.hasVersionTags and newVersionTag|default(false) %}
{% if revision.hasVersionTags and newVersionTag is not null and newVersionTag != 'silent' %}
<div class="box-header with-border bg-green color-palette">
<h3 class="box-title">New version <strong>{{ newVersionTag }}</strong></h3>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1341,10 +1341,10 @@
{% endif %}
</dt>
<dd>
{% if dataField.rawData %}
{% set translateRaw = 'revision.version_tag'|trans({'%version_tag%': dataField.rawData}) %}
{% if dataField.rawData is null or dataField.rawData == 'silent' %}
{% set translateRaw = 'field.revision_version_tag_empty'|trans({}, 'emsco-core') %}
{% else %}
{% set translateRaw = 'revision.version_tag.empty'|trans %}
{% set translateRaw = 'field.revision_version_tag'|trans({'version_tag': dataField.rawData}, 'emsco-core') %}
{% endif %}
{{ diff_text(translateRaw, false, dataField.fieldType.name, compareRawData)|raw }}
</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
{%- block label -%}{{ data.revision_label }}{%- endblock -%}

{%- block version_next_tag -%}
{%- if data.revision_version_next_tag -%}
{{- 'revision.version_tag'|trans({ '%version_tag%': data.revision_version_next_tag }) -}}
{%- if data.revision_version_next_tag is null or data.revision_version_next_tag == 'silent' -%}
{{- 'field.revision_version_tag_empty'|trans({}, 'emsco-core') -}}
{%- else -%}
{{- 'revision.version_tag.empty'|trans -}}
{{- 'field.revision_version_tag'|trans({'version_tag': data.revision_version_next_tag}, 'emsco-core') -}}
{%- endif -%}
{%- endblock -%}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class VersionOptions implements \ArrayAccess

final public const DATES_READ_ONLY = 'dates_read_only';
final public const DATES_INTERVAL_ONE_DAY = 'dates_interval_one_day';
final public const NOT_BLANK_NEW_VERSION = 'not_blank_new_version';

/**
* @param array<string, bool> $data
Expand All @@ -22,6 +23,7 @@ public function __construct(array $data)
{
$this->options[self::DATES_READ_ONLY] = $data[self::DATES_READ_ONLY] ?? true;
$this->options[self::DATES_INTERVAL_ONE_DAY] = $data[self::DATES_INTERVAL_ONE_DAY] ?? false;
$this->options[self::NOT_BLANK_NEW_VERSION] = $data[self::NOT_BLANK_NEW_VERSION] ?? false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace EMS\CoreBundle\Core\Revision\Task\DataTable;

use EMS\CoreBundle\Core\Revision\Task\TaskStatus;
use EMS\CoreBundle\Entity\Revision;

class TasksDataTableFilters
{
Expand All @@ -14,7 +15,7 @@ class TasksDataTableFilters
public array $assignee = [];
/** @var string[] */
public array $requester = [];
/** @var array<string, string|null> */
/** @var array<int, string|null> */
public array $versionNextTag = [];

public function __construct()
Expand All @@ -25,4 +26,16 @@ public function __construct()
TaskStatus::COMPLETED->value,
];
}

/**
* @return array<int, string|null>
*/
public function getVersionNextTag(): array
{
if (\in_array(null, $this->versionNextTag, true)) {
return [Revision::VERSION_BLANK, ...$this->versionNextTag];
}

return $this->versionNextTag;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private function createQueryBuilder(?TasksDataTableContext $context, string $sea
'status' => ['t.status', $context->filters->status],
'assignee' => ['t.assignee', $context->filters->assignee],
'requester' => ['t.created_by', $context->filters->requester],
'version_next' => ['r.version_next_tag', $context->filters->versionNextTag],
'version_next' => ['r.version_next_tag', $context->filters->getVersionNextTag()],
];

foreach ($filters as $name => [$column, $values]) {
Expand Down
2 changes: 2 additions & 0 deletions EMS/core-bundle/src/Entity/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class Revision implements EntityInterface, \Stringable
private Collection $releases;
private bool $selfUpdate = false;

public const VERSION_BLANK = 'silent';

public function enableSelfUpdate(): void
{
if ($this->getDraft()) {
Expand Down
11 changes: 9 additions & 2 deletions EMS/core-bundle/src/Form/DataField/VersionTagFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace EMS\CoreBundle\Form\DataField;

use EMS\CommonBundle\Common\EMSLink;
use EMS\CoreBundle\Core\ContentType\Version\VersionOptions;
use EMS\CoreBundle\Entity\DataField;
use EMS\CoreBundle\Entity\FieldType;
use EMS\CoreBundle\Service\ContentTypeService;
Expand All @@ -15,6 +16,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormRegistryInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

class VersionTagFieldType extends DataFieldType
{
Expand Down Expand Up @@ -73,15 +75,20 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$countEnvironments = $revision ? $this->environmentService->getPublishedForRevision($revision, true)->count() : 0;
}

$notBlankNewVersion = $contentType->getVersionOptions()[VersionOptions::NOT_BLANK_NEW_VERSION];

if (0 === $countEnvironments) {
$choices = $this->contentTypeService->getVersionDefault($contentType);
$placeholder = false;
} else {
$choices = $this->contentTypeService->getVersionTagsByContentType($contentType);
$choices = $this->contentTypeService->getVersionTagsByContentType($contentType, $notBlankNewVersion);
$placeholder = $notBlankNewVersion ? '' : false;
}

$builder->add('value', ChoiceType::class, [
'constraints' => $notBlankNewVersion ? [new NotBlank()] : [],
'label' => ($options['label'] ?? $fieldType->getName()),
'placeholder' => false,
'placeholder' => $placeholder,
'choices' => $choices,
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder
->add(VersionOptions::DATES_READ_ONLY, CheckboxType::class, ['required' => false])
->add(VersionOptions::DATES_INTERVAL_ONE_DAY, CheckboxType::class, ['required' => false])
->add(VersionOptions::NOT_BLANK_NEW_VERSION, CheckboxType::class, ['required' => false])
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,6 @@ revision:
draft-in-progress:
title: '%contentType% in progress'
breadcrumb: '%contentType% in progress'
version_tag: 'Yes as %version_tag%'
version_tag.empty: 'No (Silent publish)'
'An Error Occurred': 'An Error Occurred'
'Oops! An Error Occurred': 'Oops! An Error Occurred'
'The server returned a %status_code%': 'The server returned a %status_code%'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ field:
public_access: 'Public Access'
release_environment_source: 'Source Environment for publication'
release_environment_target: 'Environment for (un)publication'
revision_version_tag: 'Yes as {version_tag}'
revision_version_tag_empty: 'No (Silent publish)'
severity: Severity
singular: Singular
status: Status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@
{% if revision.hasVersionTags %}
<strong><i class="fa fa-tags margin-r-5"></i> Version</strong>
<p class="text-muted">
{% if newVersionTag|default(false) %}<span class="label label-success">New version {{ newVersionTag }}</span>{% endif %}
{% if newVersionTag is not null and newVersionTag != 'silent' %}
<span class="label label-success">New version {{ newVersionTag }}</span>
{% endif %}
{{ revision.versionTag|default('') }}
</p>
<hr/>
Expand Down Expand Up @@ -224,7 +226,7 @@

{% block revisionBody %}
<div class="box revision-view">
{% if revision.hasVersionTags and newVersionTag|default(false) %}
{% if revision.hasVersionTags and newVersionTag is not null and newVersionTag != 'silent' %}
<div class="box-header with-border bg-green color-palette">
<h3 class="box-title">New version <strong>{{ newVersionTag }}</strong></h3>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1343,10 +1343,10 @@
{% endif %}
</dt>
<dd>
{% if dataField.rawData %}
{% set translateRaw = 'revision.version_tag'|trans({'%version_tag%': dataField.rawData}) %}
{% if dataField.rawData is null or dataField.rawData == 'silent' %}
{% set translateRaw = 'field.revision_version_tag_empty'|trans({}, 'emsco-core') %}
{% else %}
{% set translateRaw = 'revision.version_tag.empty'|trans %}
{% set translateRaw = 'field.revision_version_tag'|trans({'version_tag': dataField.rawData}, 'emsco-core') %}
{% endif %}
{{ diff_text(translateRaw, false, dataField.fieldType.name, compareRawData)|raw }}
</dd>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
{%- block label -%}{{ data.revision_label }}{%- endblock -%}

{%- block version_next_tag -%}
{%- if data.revision_version_next_tag -%}
{{- 'revision.version_tag'|trans({ '%version_tag%': data.revision_version_next_tag }) -}}
{%- if data.revision_version_next_tag is null or data.revision_version_next_tag == 'silent' -%}
{{- 'field.revision_version_tag_empty'|trans({}, 'emsco-core') -}}
{%- else -%}
{{- 'revision.version_tag.empty'|trans -}}
{{- 'field.revision_version_tag'|trans({'version_tag': data.revision_version_next_tag}, 'emsco-core') -}}
{%- endif -%}
{%- endblock -%}

Expand Down
17 changes: 9 additions & 8 deletions EMS/core-bundle/src/Service/ContentTypeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use EMS\CoreBundle\Core\ContentType\ViewDefinition;
use EMS\CoreBundle\Core\UI\Menu;
use EMS\CoreBundle\Core\UI\MenuEntry;
use EMS\CoreBundle\EMSCoreBundle;
use EMS\CoreBundle\Entity\ContentType;
use EMS\CoreBundle\Entity\Environment;
use EMS\CoreBundle\Entity\FieldType;
use EMS\CoreBundle\Entity\Helper\JsonClass;
use EMS\CoreBundle\Entity\Revision;
use EMS\CoreBundle\Entity\Template;
use EMS\CoreBundle\Entity\UserInterface;
use EMS\CoreBundle\Entity\View;
Expand Down Expand Up @@ -732,9 +732,9 @@ public function getVersionDefault(ContentType $contentType): array
$versionTags = $contentType->getVersionTags();
$defaultVersion = \array_shift($versionTags);
$defaultVersionLabel = $this->translator->trans(
'revision.version_tag',
'field.revision_version_tag',
['%version_tag%' => $defaultVersion],
EMSCoreBundle::TRANS_DOMAIN
'emsco-core'
);

return [$defaultVersionLabel => $defaultVersion];
Expand All @@ -743,7 +743,7 @@ public function getVersionDefault(ContentType $contentType): array
/**
* @return array<string, ?string>
*/
public function getVersionTagsByContentType(ContentType $contentType): array
public function getVersionTagsByContentType(ContentType $contentType, ?bool $notBlankNewVersion = false): array
{
if (!$contentType->hasVersionTags()) {
return [];
Expand All @@ -752,15 +752,16 @@ public function getVersionTagsByContentType(ContentType $contentType): array
$versionTags = $contentType->getVersionTags();
$versionTagsLabels = \array_map(function (string $versionTag) {
return $this->translator->trans(
'revision.version_tag',
'field.revision_version_tag',
['%version_tag%' => $versionTag],
EMSCoreBundle::TRANS_DOMAIN
'emsco-core'
);
}, $versionTags);

$emptyLabel = $this->translator->trans('revision.version_tag.empty', [], EMSCoreBundle::TRANS_DOMAIN);
$emptyLabel = $this->translator->trans('field.revision_version_tag_empty', [], 'emsco-core');
$emptyValue = ($notBlankNewVersion ? Revision::VERSION_BLANK : null);

return [$emptyLabel => null] + \array_combine($versionTagsLabels, $versionTags);
return [$emptyLabel => $emptyValue] + \array_combine($versionTagsLabels, $versionTags);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion EMS/core-bundle/src/Service/PublishService.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ private function publishVersion(Revision $revision, Environment $environment, ?s
$contentType = $revision->giveContentType();
$selectedVersionTag = $revision->getVersionNextTag();

if (null === $selectedVersionTag) {
if (\in_array($selectedVersionTag, [null, Revision::VERSION_BLANK], true)) {
$revision->removeFromRawData($contentType->getVersionTagField());

return;
}

Expand Down

0 comments on commit 4c79092

Please sign in to comment.