christian ewigfrost
2017-12-14 14:57:50 UTC
I want to prevent a BE user from inputting undesired property values for records, let's say for the property IPv4. I wrote an evaluation class for this:
class IPv4Evaluation
{
/**
* @param string $value
* @param string $is_in
* @param bool $set
* @return string
*/
public function evaluateFieldValue($value, $is_in, &$set)
{
if (!filter_var($value, FILTER_VALIDATE_IP)){
$value = 'Fehlerhafte Eingabe (IPv4): .conf wird nicht angelegt';
/** @var FlashMessage $message */
$message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
'.conf wird nicht angelegt',
'Fehlerhafte Eingabe (IPv4):',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
TRUE
);
/** @var $flashMessageService FlashMessageService */
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$flashMessageService->getMessageQueueByIdentifier()->enqueue($message);
}
return $value;
}
}
But the only thing that it does while adding it to the field of the specific classe's TCA is to change the value to another value. I also use a flash message to warn the user that the inserted value is false. But i really need the record not to be saved in this situation. So in short: If the BE user does insert an undesired value and he wants to save it, the record will either not be created or not be saved, if he was just editing an existing record. How do i do this?
Maybe i should use a Datamapper Hook for this instead of an eval class?
class IPv4Evaluation
{
/**
* @param string $value
* @param string $is_in
* @param bool $set
* @return string
*/
public function evaluateFieldValue($value, $is_in, &$set)
{
if (!filter_var($value, FILTER_VALIDATE_IP)){
$value = 'Fehlerhafte Eingabe (IPv4): .conf wird nicht angelegt';
/** @var FlashMessage $message */
$message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
'.conf wird nicht angelegt',
'Fehlerhafte Eingabe (IPv4):',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
TRUE
);
/** @var $flashMessageService FlashMessageService */
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$flashMessageService->getMessageQueueByIdentifier()->enqueue($message);
}
return $value;
}
}
But the only thing that it does while adding it to the field of the specific classe's TCA is to change the value to another value. I also use a flash message to warn the user that the inserted value is false. But i really need the record not to be saved in this situation. So in short: If the BE user does insert an undesired value and he wants to save it, the record will either not be created or not be saved, if he was just editing an existing record. How do i do this?
Maybe i should use a Datamapper Hook for this instead of an eval class?