Commit 7a4805ab authored by Tino Goratsch's avatar Tino Goratsch

- converted the System module to use the new validation facility

parent 6ca2774b
<?php
namespace ACP3\Core\Validator\ValidationRules;
use ACP3\Core\Lang;
/**
* Class LanguagePackExistsValidationRule
* @package ACP3\Core\Validator\ValidationRules
*/
class LanguagePackExistsValidationRule extends AbstractValidationRule
{
const NAME = 'language_pack_exists';
/**
* @var \ACP3\Core\Lang
*/
protected $lang;
/**
* LanguagePackExistsValidationRule constructor.
*
* @param \ACP3\Core\Lang $lang
*/
public function __construct(Lang $lang)
{
$this->lang = $lang;
}
/**
* @inheritdoc
*/
public function isValid($data, $field = '', array $extra = [])
{
if (is_array($data) && array_key_exists($field, $data)) {
return $this->isValid($data[$field], $field, $extra);
}
return $this->lang->languagePackExists($data);
}
}
\ No newline at end of file
<?php
namespace ACP3\Core\Validator\ValidationRules;
/**
* Class TimeZoneExistsValidationRule
* @package ACP3\Core\Validator\ValidationRules
*/
class TimeZoneExistsValidationRule extends AbstractValidationRule
{
const NAME = 'time_zone_exists';
/**
* @inheritdoc
*/
public function isValid($data, $field = '', array $extra = [])
{
if (is_array($data) && array_key_exists($field, $data)) {
return $this->isValid($data[$field], $field, $extra);
}
$bool = true;
try {
new \DateTimeZone($data);
} catch (\Exception $e) {
$bool = false;
}
return $bool;
}
}
\ No newline at end of file
......@@ -38,6 +38,12 @@ services:
tags:
- { name: core.validator.validation_rule }
core.validator.validation_rules.language_pack_exists_validation_rule:
class: ACP3\Core\Validator\ValidationRules\LanguagePackExistsValidationRule
arguments: [@core.lang]
tags:
- { name: core.validator.validation_rule }
core.validator.validation_rules.min_length_validation_rule:
class: ACP3\Core\Validator\ValidationRules\MinLengthValidationRule
tags:
......@@ -70,6 +76,11 @@ services:
tags:
- { name: core.validator.validation_rule }
core.validator.validation_rules.time_zone_exists_validation_rule:
class: ACP3\Core\Validator\ValidationRules\TimeZoneExistsValidationRule
tags:
- { name: core.validator.validation_rule }
core.validator.abstract:
abstract: true
arguments: ['@core.lang', @core.validator, '@core.validator.rules.misc']
......
......@@ -242,6 +242,7 @@
<item key="select_date_format">Bitte wählen Sie aus, ob das lange oder das kurze Datumsformat verwendet werden soll.</item>
<item key="select_editor">Bitte wählen Sie aus, mit welchem Editor Sie Ihre Einträge erstellen wollen.</item>
<item key="select_language">Bitte wählen Sie aus, in welcher Sprache Sie die Website angezeigt bekommen möchten.</item>
<item key="select_mailer_type">Bitte wählen Sie den zu verwendenten Mailertyp aus.</item>
<item key="select_menu_item">Bitte wählen Sie einen der oben stehenden Menüpunkte aus, um zur gewünschten Aktion zu gelangen.</item>
<item key="select_online_maintenance">Bitte wählen Sie aus, ob sich die Seite im Wartungsmodus befinden soll oder nicht.</item>
<item key="select_records_per_page">Bitte wählen Sie aus, wie viele Datensätze pro Seite angezeigt werden sollen.</item>
......
......@@ -242,6 +242,7 @@
<item key="select_date_format">Please select whether the long or the short date format to be used.</item>
<item key="select_editor">Please select whether you want to use a WYSIWYG editor or a simple textarea.</item>
<item key="select_language">Please select the language in which you want to see the website.</item>
<item key="select_mailer_type">Please select the mailer type.</item>
<item key="select_menu_item">Please choose from one of the menu items above to get to the desired action.</item>
<item key="select_online_maintenance">Please select whether the maintenance mode should be turned on or off.</item>
<item key="select_records_per_page">Please select how many records per page to display.</item>
......
......@@ -7,6 +7,7 @@ parameters:
system.model.modulerepository.fqdn: 'ACP3\Modules\ACP3\System\Model\ModuleRepository'
system.model.settingsrepository.fqdn: 'ACP3\Modules\ACP3\System\Model\SettingsRepository'
system.validator.settings.fqdn: 'ACP3\Modules\ACP3\System\Validator\Settings'
system.validator.validation_rules.is_wysiwyg_editor_validation_rule.fqdn: 'ACP3\Modules\ACP3\System\Validator\ValidationRules\IsWysiwygEditorValidationRule'
system.installer.schema.fqdn: 'ACP3\Modules\ACP3\System\Installer\Schema'
system.installer.migration.fqdn: 'ACP3\Modules\ACP3\System\Installer\Migration'
......@@ -37,7 +38,13 @@ services:
system.validator.settings:
class: %system.validator.settings.fqdn%
arguments: ['@core.lang', @core.validator, '@core.validator.rules.misc', '@core.validator.rules.date', '@core.validator.rules.router', '@service_container']
parent: core.validator.abstract
system.validator.validation_rules.is_wysiwyg_editor_validation_rule:
class: %system.validator.validation_rules.is_wysiwyg_editor_validation_rule.fqdn%
arguments: [@service_container]
tags:
- { name: core.validator.validation_rule }
system.installer.schema:
class: %system.installer.schema.fqdn%
......
<?php
namespace ACP3\Modules\ACP3\System\Validator\ValidationRules;
use ACP3\Core\Validator\ValidationRules\AbstractValidationRule;
use ACP3\Core\WYSIWYG\AbstractWYSIWYG;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class IsWysiwygEditorValidationRule
* @package ACP3\Modules\ACP3\System\Validator\ValidationRules
*/
class IsWysiwygEditorValidationRule extends AbstractValidationRule
{
const NAME = 'system_is_wysiwyg_editor';
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* IsWysiwygEditorValidationRule constructor.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* @inheritdoc
*/
public function isValid($data, $field = '', array $extra = [])
{
if (is_array($data) && array_key_exists($field, $data)) {
return $this->isValid($data[$field], $field, $extra);
}
return $this->isValidWysiwygEditor($data);
}
/**
* @param string $data
*
* @return bool
*/
protected function isValidWysiwygEditor($data)
{
return !empty($data) && $this->container->has($data) && $this->container->get($data) instanceof AbstractWYSIWYG;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment