Commit b00ce3cb authored by Tino Goratsch's avatar Tino Goratsch

next part at trying to get the ACP3 working without the SEO module

parent e8927524
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Validation\Event;
use ACP3\Core\Validation\Validator;
use Symfony\Component\EventDispatcher\Event;
class FormValidationEvent extends Event
{
/**
* @var Validator
*/
private $validator;
/**
* @var array
*/
private $formData;
/**
* @var array
*/
private $extra;
/**
* FormValidationEvent constructor.
* @param Validator $validator
* @param array $formData
* @param array $extra
*/
public function __construct(
Validator $validator,
array $formData,
array $extra = []
) {
$this->validator = $validator;
$this->formData = $formData;
$this->extra = $extra;
}
/**
* @return Validator
*/
public function getValidator()
{
return $this->validator;
}
/**
* @return array
*/
public function getFormData()
{
return $this->formData;
}
/**
* @return array
*/
public function getExtra()
{
return $this->extra;
}
}
<?php
namespace ACP3\Core\Validation;
use ACP3\Core\Validation\Event\FormValidationEvent;
use ACP3\Core\Validation\Exceptions\ValidationFailedException;
use ACP3\Core\Validation\Exceptions\ValidationRuleNotFoundException;
use ACP3\Core\Validation\ValidationRules\ValidationRuleInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Class Validator
......@@ -11,6 +13,10 @@ use ACP3\Core\Validation\ValidationRules\ValidationRuleInterface;
*/
class Validator
{
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* @var \ACP3\Core\Validation\ValidationRules\ValidationRuleInterface[]
*/
......@@ -24,6 +30,15 @@ class Validator
*/
protected $constraints = [];
/**
* Validator constructor.
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
/**
* @param \ACP3\Core\Validation\ValidationRules\ValidationRuleInterface $validationRule
*
......@@ -97,6 +112,22 @@ class Validator
return str_replace('_', '-', $field);
}
/**
* @param string $eventName
* @param array $formData
* @param array $extra
*/
public function dispatchValidationEvent($eventName, array $formData, array $extra = [])
{
$this->eventDispatcher->dispatch($eventName, new FormValidationEvent($this, $formData, $extra));
}
/**
* Validates a form
*
* @throws ValidationFailedException
* @throws ValidationRuleNotFoundException
*/
public function validate()
{
$this->errors = [];
......
services:
core.validator:
class: ACP3\Core\Validation\Validator
arguments:
- '@core.event_dispatcher'
core.validation.validation_rules.birthday_validation_rule:
class: ACP3\Core\Validation\ValidationRules\BirthdayValidationRule
......
......@@ -8,7 +8,6 @@ namespace ACP3\Modules\ACP3\Articles\Validation;
use ACP3\Core;
use ACP3\Modules\ACP3\Menus;
use ACP3\Modules\ACP3\Seo\Validation\ValidationRules\UriAliasValidationRule;
/**
* Class AdminFormValidation
......@@ -87,21 +86,18 @@ class AdminFormValidation extends Core\Validation\AbstractFormValidation
'extra' => [
'length' => 3
]
])
->addConstraint(
UriAliasValidationRule::class,
[
'data' => $formData,
'field' => 'alias',
'message' => $this->translator->t('seo', 'alias_unallowed_characters_or_exists'),
'extra' => [
'path' => $this->uriAlias
]
]);
if ($this->acl->hasPermission('admin/menus/items/create') === true && isset($formData['create']) === true) {
$this->validateMenuItem($formData);
}
$this->validator->dispatchValidationEvent(
'seo.validation.validate_uri_alias',
$formData,
['path' => $this->uriAlias]
);
$this->validator->validate();
}
......
......@@ -4,7 +4,6 @@ namespace ACP3\Modules\ACP3\Files\Validation;
use ACP3\Core;
use ACP3\Modules\ACP3\Categories;
use ACP3\Modules\ACP3\Files\Validation\ValidationRules\IsExternalFileValidationRule;
use ACP3\Modules\ACP3\Seo\Validation\ValidationRules\UriAliasValidationRule;
/**
* Class AdminFormValidation
......@@ -81,16 +80,6 @@ class AdminFormValidation extends Core\Validation\AbstractFormValidation
'file' => $this->file
]
])
->addConstraint(
UriAliasValidationRule::class,
[
'data' => $formData,
'field' => 'alias',
'message' => $this->translator->t('seo', 'alias_unallowed_characters_or_exists'),
'extra' => [
'path' => $this->uriAlias
]
])
->addConstraint(
Categories\Validation\ValidationRules\CategoryExistsValidationRule::class,
[
......@@ -113,6 +102,12 @@ class AdminFormValidation extends Core\Validation\AbstractFormValidation
]);
}
$this->validator->dispatchValidationEvent(
'seo.validation.validate_uri_alias',
$formData,
['path' => $this->uriAlias]
);
$this->validator->validate();
}
}
......@@ -2,7 +2,6 @@
namespace ACP3\Modules\ACP3\Gallery\Validation;
use ACP3\Core;
use ACP3\Modules\ACP3\Seo\Validation\ValidationRules\UriAliasValidationRule;
/**
* Class GalleryFormValidation
......@@ -47,18 +46,14 @@ class GalleryFormValidation extends Core\Validation\AbstractFormValidation
'data' => $formData,
'field' => 'title',
'message' => $this->translator->t('gallery', 'type_in_gallery_title')
])
->addConstraint(
UriAliasValidationRule::class,
[
'data' => $formData,
'field' => 'alias',
'message' => $this->translator->t('seo', 'alias_unallowed_characters_or_exists'),
'extra' => [
'path' => $this->uriAlias
]
]);
$this->validator->dispatchValidationEvent(
'seo.validation.validate_uri_alias',
$formData,
['path' => $this->uriAlias]
);
$this->validator->validate();
}
}
......@@ -4,7 +4,6 @@ namespace ACP3\Modules\ACP3\News\Validation;
use ACP3\Core;
use ACP3\Core\Validation\ValidationRules\ExternalLinkValidationRule;
use ACP3\Modules\ACP3\Categories;
use ACP3\Modules\ACP3\Seo\Validation\ValidationRules\UriAliasValidationRule;
/**
* Class AdminFormValidation
......@@ -67,18 +66,14 @@ class AdminFormValidation extends Core\Validation\AbstractFormValidation
'data' => $formData,
'field' => ['link_title', 'uri', 'target'],
'message' => $this->translator->t('news', 'complete_hyperlink_statements')
])
->addConstraint(
UriAliasValidationRule::class,
[
'data' => $formData,
'field' => 'alias',
'message' => $this->translator->t('seo', 'alias_unallowed_characters_or_exists'),
'extra' => [
'path' => $this->uriAlias
]
]);
$this->validator->dispatchValidationEvent(
'seo.validation.validate_uri_alias',
$formData,
['path' => $this->uriAlias]
);
$this->validator->validate();
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Seo\Event\Listener;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Validation\Event\FormValidationEvent;
use ACP3\Modules\ACP3\Seo\Validation\ValidationRules\UriAliasValidationRule;
class OnSeoValidationValidateUriAlias
{
/**
* @var Translator
*/
private $translator;
/**
* OnSeoValidationValidateUriAlias constructor.
* @param Translator $translator
*/
public function __construct(Translator $translator)
{
$this->translator = $translator;
}
/**
* @param FormValidationEvent $event
*/
public function validateUriAlias(FormValidationEvent $event)
{
$event
->getValidator()
->addConstraint(
UriAliasValidationRule::class,
[
'data' => $event->getFormData(),
'field' => 'alias',
'message' => $this->translator->t('seo', 'alias_unallowed_characters_or_exists'),
'extra' => $event->getExtra()
]
);
}
}
......@@ -17,13 +17,20 @@ services:
tags:
- { name: core.eventListener, event: core.layout.meta, method: renderSeoMetaTags }
seo.event.on_layout.seo_render_form_fields_listener:
seo.event.on_layout_seo_render_form_fields_listener:
class: ACP3\Modules\ACP3\Seo\Event\Listener\OnLayoutSeoRenderFormFieldsListener
arguments:
- '@core.view'
tags:
- { name: core.eventListener, event: seo.layout.render_form_fields, method: renderSeoFormFields }
seo.event.on_validation_validate_uri_alias_listener:
class: ACP3\Modules\ACP3\Seo\Event\Listener\OnSeoValidationValidateUriAlias
arguments:
- '@core.lang'
tags:
- { name: core.eventListener, event: seo.validation.validate_uri_alias, method: validateUriAlias }
seo.event.update_seo_cache_on_model_after_save_listener:
class: ACP3\Modules\ACP3\Seo\Event\Listener\UpdateSeoCacheOnModelAfterSaveListener
arguments:
......
......@@ -2,7 +2,6 @@
namespace ACP3\Modules\ACP3\Seo\Validation;
use ACP3\Core;
use ACP3\Modules\ACP3\Seo\Validation\ValidationRules\UriAliasValidationRule;
/**
* Class AdminFormValidation
......@@ -41,16 +40,6 @@ class AdminFormValidation extends Core\Validation\AbstractFormValidation
'field' => 'uri',
'message' => $this->translator->t('seo', 'type_in_valid_resource')
])
->addConstraint(
UriAliasValidationRule::class,
[
'data' => $formData,
'field' => 'alias',
'message' => $this->translator->t('seo', 'alias_unallowed_characters_or_exists'),
'extra' => [
'path' => $this->uriAlias
]
])
->addConstraint(
Core\Validation\ValidationRules\InArrayValidationRule::class,
[
......@@ -62,6 +51,12 @@ class AdminFormValidation extends Core\Validation\AbstractFormValidation
]
]);
$this->validator->dispatchValidationEvent(
'seo.validation.validate_uri_alias',
$formData,
['path' => $this->uriAlias]
);
$this->validator->validate();
}
}
services:
core.validator:
class: ACP3\Core\Validation\Validator
arguments:
- '@core.event_dispatcher'
core.validation.validation_rules.birthday_validation_rule:
class: ACP3\Core\Validation\ValidationRules\BirthdayValidationRule
......
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