We changed our privacy policy. Read more.

New answers tagged

1

Update 2021-09-24 The actual issue is that entries fields can't hold references to drafts only, only to 'real' entries. Drafts have their own ID, but they aren't real entries. The entries field validates this, so any ID that doesn't belong to a realy entries is silently discarded. If the draft belongs to an entry that is already live, the solution is to add ...


3

You can use entry queries to fetch the entries and the elements service to save them. You can access the element service using Craft::$app->elements. Use Craft::$app->elements->saveElement($entry); to save an entry (or any other element). The best place to put business logic is a service class that you can then call from your controllers. So ...


2

Rather than throwing an exception when the filesize is too large, you should be adding a validation error, which should be handled correctly. use craft\base\Model; use craft\elements\Asset; use craft\events\DefineRulesEvent; use craft\helpers\ArrayHelper; use yii\base\Event; Event::on( Asset::class, Model::EVENT_DEFINE_RULES, function(...


Top 50 recent answers are included