Skip to content

Commit

Permalink
Merge branch '5.x' into 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidmattei committed Dec 16, 2024
2 parents 3afb40e + 77f1305 commit cd97ee6
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ public function getTemplateContentType(string $contentTypeName): ContentType
return $this->templateContentTypes[$contentTypeName];
}

public function hasTemplateContentType(string $contentTypeName): bool
{
if (empty($this->templateContentTypes)) {
throw new \RuntimeException('Missing config EMSCH_TEMPLATES');
}

return isset($this->templateContentTypes[$contentTypeName]);
}

/**
* @return ContentType[]
*/
Expand Down
20 changes: 20 additions & 0 deletions EMS/client-helper-bundle/src/Helper/Templating/TemplateBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace EMS\ClientHelperBundle\Helper\Templating;

use EMS\ClientHelperBundle\Exception\SingleResultException;
use EMS\ClientHelperBundle\Helper\Builder\AbstractBuilder;
use EMS\ClientHelperBundle\Helper\Environment\Environment;

Expand Down Expand Up @@ -71,4 +72,23 @@ public function isFresh(Environment $environment, TemplateName $templateName, in

return $contentType->isLastPublishedAfterTime($time);
}

public function exists(Environment $environment, TemplateName $templateName): bool
{
$settings = $this->settings($environment);
if ($environment->isLocalPulled()) {
return null !== $environment->getLocal()->getTemplates($settings)->find($templateName);
}
if (!$settings->hasTemplateContentType($templateName->getContentType())) {
return false;
}

try {
$this->buildTemplate($environment, $templateName);
} catch (SingleResultException) {
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ public function exists($name): bool
if (null === $this->environmentHelper->getCurrentEnvironment()) {
return false;
}
if (!TemplateName::validate($name)) {
return false;
}
$environment = $this->getEnvironment();
$templateName = new TemplateName($name);

return TemplateName::validate($name);
return $this->builder->exists($environment, $templateName);
}

private function getEnvironment(): Environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@ public function getName(): string
*/
public function getDataSource(): array
{
$source = ['key' => $this->source['key']];

foreach ($this->locales as $locale) {
if (isset($this->source['label_'.$locale])) {
$source['label_'.$locale] = $this->source['label_'.$locale];
}
}

return $source;
return \array_filter($this->source, fn ($key) => 'key' === $key || \str_starts_with($key, 'label_'), ARRAY_FILTER_USE_KEY);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public function __construct(string $directory)
{
$path = $directory.\DIRECTORY_SEPARATOR.self::DIRECTORY;

if (\file_exists($path)) {
foreach (Finder::create()->in($path)->files()->name('*.yaml') as $file) {
$this->files[] = new TranslationFile($file);
}
if (!\file_exists($path)) {
return;
}
foreach (Finder::create()->in($path)->files()->name('*.yaml') as $file) {
$this->files[] = new TranslationFile($file);
}
}

Expand Down
19 changes: 9 additions & 10 deletions demo/skeleton/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ emsch_login:
config:
controller: emsch.controller.security.login
path: /login
method: [ POST, GET ]
method: [POST, GET]
template_static: template/security/login.html.twig
ems:
config:
Expand All @@ -135,29 +135,28 @@ ems_versions:
template_static: template/security/versions.html.twig
ems_version_new:
config:
method: [ GET ]
method: [GET]
path: /ems/versions/new
defaults: { _authenticated: true }
template_static: template/security/version.html.twig
ems_version_detail:
config:
method: [ GET ]
path: /ems/versions/{ouuid}
method: [GET]
path: '/ems/versions/{ouuid}'
defaults: { _authenticated: true }
query: '{"query":{"bool":{"must":[{"term":{"_contenttype":{"value":"release"}}},{"term":{"_id":{"value":"%ouuid%"}}}]}}}'
template_static: template/security/version.html.twig
ems_version_create:
config:
method: [ POST ]
method: [POST]
path: /ems/versions/create
controller: 'EMS\ClientHelperBundle\Controller\ApiController::createDocumentFromForm'
defaults: { _authenticated: true, apiName: backend, contentType: release, redirectUrl: '/ems/versions/%ouuid%', validationTemplate: '@EMSCH/template/security/version_validate.twig' }
defaults: { _authenticated: true, apiName: backend, contentType: release, redirectUrl: /ems/versions/%ouuid%, validationTemplate: '@EMSCH/template/security/version_validate.twig' }
query: '{"query":{"bool":{"must":[{"term":{"_contenttype":{"value":"release"}}},{"term":{"_id":{"value":"%id%"}}}]}}}'
ems_version_update:
config:
method: [ POST ]
path: /ems/versions/{ouuid}
method: [POST]
path: '/ems/versions/{ouuid}'
controller: 'EMS\ClientHelperBundle\Controller\ApiController::updateDocumentFromForm'
defaults: { _authenticated: true, apiName: backend, contentType: release, redirectUrl: '/ems/versions/%ouuid%', validationTemplate: '@EMSCH/template/security/version_validate.twig' }
defaults: { _authenticated: true, apiName: backend, contentType: release, redirectUrl: /ems/versions/%ouuid%, validationTemplate: '@EMSCH/template/security/version_validate.twig' }
query: '{"query":{"bool":{"must":[{"term":{"_contenttype":{"value":"release"}}},{"term":{"_id":{"value":"%id%"}}}]}}}'

2 changes: 1 addition & 1 deletion demo/skeleton/template/variables.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% set wyiwygReplaces = {
'src="https://www.youtube.com/': 'allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen src="https://www.youtube-nocookie.com/',
} %}
{% do emsch_assets_version(include('@EMSCH/template/asset_hash.twig'), null) %}
{% do emsch_assets_version(ems_template_exists('@EMSCH/template/asset_hash.twig') ? include('@EMSCH/template/asset_hash.twig') : 'demo', null) %}
{% set baseUrl = '/' %}
{% if app.user %}
{% set baseUrl = "/channel/#{trans_default_domain}" %}
Expand Down
10 changes: 10 additions & 0 deletions demo/skeleton/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ ems:
back_to_ems: 'Retour à eMS'
ems_form:
loading: 'en cours de chargement...'
emsch:
security:
exception:
bad_credentials: 'Nom d''utilisateur ou mot de passe invalide'
error: 'Une erreur s''est produite !'
form:
password: 'Mot de passe'
submit: 'Se connecter'
username: 'Nom d''utilisateur'
features:
discover: 'Découvrez toutes les fonctionnalités'
files_browse: 'Choisir des fichiers'
Expand All @@ -41,6 +50,7 @@ js:
language:
selection: 'select language'
locale: Français
login: 'Se connecter'
missing:
description: 'Changer de langue pour voir les versions alternatives.'
title: 'Ce contenu n''est pas disponible en français'
Expand Down
10 changes: 10 additions & 0 deletions demo/skeleton/translations/messages.nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ ems:
back_to_ems: 'Terug naar eMS'
ems_form:
loading: 'bezig met laden...'
emsch:
security:
exception:
bad_credentials: 'Ongeldige gebruikersnaam of wachtwoord'
error: 'Er is iets fout gegaan!'
form:
password: Wachtwoord
submit: Login
username: Gebruikersnaam
features:
discover: 'Ontdek alle features'
files_browse: 'Kiezen bestanden'
Expand All @@ -41,6 +50,7 @@ js:
language:
selection: 'select language'
locale: Nederlands
login: Login
missing:
description: 'Wijzig de taal om alternatieve versies te zien.'
title: 'Deze inhoud is niet beschikbaar in het Nederlands'
Expand Down

0 comments on commit cd97ee6

Please sign in to comment.