Skip to content

Add a field callback right before the content is saved/collected inside the transaction during element save #17004

Closed Answered by brandonkelly
Anubarak asked this question in Ideas
Discussion options

You must be logged in to vote

Your field type could override isValueEmpty() and just have it always return false regardless of the actual value.

Alternatively, you could define a new class which implements craft\base\Serializable and stores the existing value on a property within it, and generates a new one via its serialize() method if it’s null.

use craft\base\Serializable;

class MyGeneratedValue implements Serializable
{
    public function __construct(
        private readonly ?string $value,
    ) {
    }

    public function serialize(): string
    {
        if (!isset($this->value)) {
            // define it here
        }

        return $this->value;
    }
}

Then have your field type’s normalizeValue() meth…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants