-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The event can be used to check the entire model and pass error messages for one or more properties
- Loading branch information
Showing
5 changed files
with
107 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
/** | ||
* This file is part of contao-community-alliance/dc-general. | ||
* | ||
* (c) 2013-2024 Contao Community Alliance. | ||
* (c) 2013-2025 Contao Community Alliance. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
|
@@ -18,17 +18,13 @@ | |
* @author Stefan Heimes <[email protected]> | ||
* @author Sven Baumann <[email protected]> | ||
* @author Richard Henkenjohann <[email protected]> | ||
* @copyright 2013-2024 Contao Community Alliance. | ||
* @copyright 2013-2025 Contao Community Alliance. | ||
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later | ||
* @filesource | ||
*/ | ||
|
||
namespace ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView; | ||
|
||
use Contao\BackendUser; | ||
use Contao\CoreBundle\Intl\Locales; | ||
use Contao\Image; | ||
use Contao\System; | ||
use ContaoCommunityAlliance\Contao\Bindings\ContaoEvents; | ||
use ContaoCommunityAlliance\Contao\Bindings\Events\Backend\AddToUrlEvent; | ||
use ContaoCommunityAlliance\Contao\Bindings\Events\Controller\RedirectEvent; | ||
|
@@ -38,29 +34,34 @@ | |
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetEditMaskSubHeadlineEvent; | ||
use ContaoCommunityAlliance\DcGeneral\Contao\View\Contao2BackendView\Event\GetEditModeButtonsEvent; | ||
use ContaoCommunityAlliance\DcGeneral\Controller\ControllerInterface; | ||
use ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface; | ||
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\BasicDefinitionInterface; | ||
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\PropertiesDefinitionInterface; | ||
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\LegendInterface; | ||
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\PaletteInterface; | ||
use ContaoCommunityAlliance\DcGeneral\Data\DataProviderInterface; | ||
use ContaoCommunityAlliance\DcGeneral\Data\DefaultEditInformation; | ||
use ContaoCommunityAlliance\DcGeneral\Data\EditInformationInterface; | ||
use ContaoCommunityAlliance\DcGeneral\Data\ModelId; | ||
use ContaoCommunityAlliance\DcGeneral\Data\ModelInterface; | ||
use ContaoCommunityAlliance\DcGeneral\Data\MultiLanguageDataProviderInterface; | ||
use ContaoCommunityAlliance\DcGeneral\Data\PropertyValueBag; | ||
use ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface; | ||
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\BasicDefinitionInterface; | ||
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Definition\PropertiesDefinitionInterface; | ||
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\LegendInterface; | ||
use ContaoCommunityAlliance\DcGeneral\DataDefinition\Palette\PaletteInterface; | ||
use ContaoCommunityAlliance\DcGeneral\DcGeneralEvents; | ||
use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface; | ||
use ContaoCommunityAlliance\DcGeneral\Event\EnforceModelRelationshipEvent; | ||
use ContaoCommunityAlliance\DcGeneral\Event\PostPersistModelEvent; | ||
use ContaoCommunityAlliance\DcGeneral\Event\PreEditModelEvent; | ||
use ContaoCommunityAlliance\DcGeneral\Event\PrePersistModelEvent; | ||
use ContaoCommunityAlliance\DcGeneral\Event\ValidateModelEvent; | ||
use ContaoCommunityAlliance\DcGeneral\Exception\DcGeneralInvalidArgumentException; | ||
use ContaoCommunityAlliance\DcGeneral\Exception\DcGeneralRuntimeException; | ||
use ContaoCommunityAlliance\DcGeneral\InputProviderInterface; | ||
use ContaoCommunityAlliance\DcGeneral\SessionStorageInterface; | ||
use ContaoCommunityAlliance\Translator\TranslatorInterface; | ||
use Contao\BackendUser; | ||
use Contao\CoreBundle\Intl\Locales; | ||
use Contao\Image; | ||
use Contao\System; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
|
@@ -563,6 +564,12 @@ protected function buildFieldSet($widgetManager, $palette, $propertyValues) | |
$propName, | ||
$widgetManager->decodeValue($propName, $propertyValues->getPropertyValue($propName)) | ||
); | ||
if ($propertyValues->isPropertyValueInvalid($propName)) { | ||
$rawValues->markPropertyValueAsInvalid( | ||
$propName, | ||
$propertyValues->getPropertyValueErrors($propName) | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -994,6 +1001,12 @@ public function execute() | |
|
||
// Update the model - the model might add some more errors to the propertyValueBag via exceptions. | ||
$controller->updateModelFromPropertyBag($model, $propertyValues); | ||
|
||
// Validate whole model. | ||
$dispatcher->dispatch( | ||
new ValidateModelEvent($environment, $model, $propertyValues), | ||
ValidateModelEvent::NAME | ||
); | ||
} | ||
|
||
$fieldSets = $this->buildFieldSet($widgetManager, $palette, $propertyValues); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of contao-community-alliance/dc-general. | ||
* | ||
* (c) 2013-2025 Contao Community Alliance. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* This project is provided in good faith and hope to be usable by anyone. | ||
* | ||
* @package contao-community-alliance/dc-general | ||
* @author Ingolf Steinhardt <[email protected]> | ||
* @copyright 2013-2025 Contao Community Alliance. | ||
* @license https://github.com/contao-community-alliance/dc-general/blob/master/LICENSE LGPL-3.0-or-later | ||
* @filesource | ||
*/ | ||
|
||
namespace ContaoCommunityAlliance\DcGeneral\Event; | ||
|
||
use ContaoCommunityAlliance\DcGeneral\Data\ModelInterface; | ||
use ContaoCommunityAlliance\DcGeneral\Data\PropertyValueBagInterface; | ||
use ContaoCommunityAlliance\DcGeneral\EnvironmentInterface; | ||
|
||
/** | ||
* This event is emitted when a submitted and updated model has to be validated. | ||
* | ||
* This is triggered after the model has been updated but before rendering the edit mask and pre-persist. | ||
*/ | ||
class ValidateModelEvent extends AbstractModelAwareEvent | ||
{ | ||
/** @psalm-suppress MissingClassConstType */ | ||
public const NAME = 'dc-general.model.validate'; | ||
|
||
/** | ||
* Create a new model aware event. | ||
* | ||
* @param EnvironmentInterface $environment The environment. | ||
* @param ModelInterface $model The model being validated. | ||
* @param PropertyValueBagInterface $propertyValueBag The property values. | ||
*/ | ||
public function __construct( | ||
EnvironmentInterface $environment, | ||
ModelInterface $model, | ||
private readonly PropertyValueBagInterface $propertyValueBag | ||
) { | ||
parent::__construct($environment, $model); | ||
} | ||
|
||
public function getPropertyValueBag(): PropertyValueBagInterface | ||
{ | ||
return $this->propertyValueBag; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters