TYPO3 - TCA - change the value of one field when another changes

109 Views Asked by At

I have TYPO3 11.5.26.
I have a custom entity.
I generated a TCA configuration.

I need to change the value of a field on certain conditions of another value field.

Example:
If "deadline field date" <= today then "State field value" = "open" else "closed"

How can I do that?

2

There are 2 best solutions below

0
On BEST ANSWER

The only clean way to achive that is to implement a Scheduler Task. A good way is to use a console command. Here is a tutorial how to implement:

https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/CommandControllers/Tutorial.html#console-command-tutorial

In the execute() method of the command you can then iterate all your custom entities, check the deadline field and change the state field if needed. That would look something like this:

public function execute()
{
    $allMyEntities = $myEntityRepository->findAll();
    foreach($allMyEntities as $myEntity)
    {
        if($myEntity->getDealine() <= $today)
        {
            $myEntity->setState("closed");
            $myEntityRepository->update($myEntity);
        }
    }
}
0
On

That's not possible to handle clean in the database. TCA can only work if the record is edited and saved.

That value is dynamic as it changes with the time when the record is evaluated/ read.
Though it is no data value but an evaluation value. You could build a getter for this value in the repository class or set the value in the controller.