Skip to main content
4 votes
Accepted

How to add the option for a link to select a target, e.g. open link in new window? [CKEDITOR Plugin]

Don't include EditorClass.create in the JavaScript config. Creating the CKEditor instance is handled by the Craft plugin. The JavaScript code in the configuration should just return an object with ...
MoritzLost's user avatar
  • 11.9k
4 votes

Setting valueless boolean attributes with the tag function

If an attribute is set to true, it will get added without a value. {{ tag('input', { id: idVar, name: nameVar, required: true }) }} Also, if it is set to null or false, it will be omitted,...
Brandon Kelly's user avatar
3 votes
Accepted

Add custom attribute to standard element from plugin

Another approach is to use the following event to attach a behavior Event::on(Asset::class, Asset::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) { $event->behaviors[] = ...
Robin Schambach's user avatar
3 votes
Accepted

Model values assignment issue

There is a second parameter in your setAttributes() function. This parameter is true per default and checks if the attribute is safe so you either have to declare all safe attributes in your records ...
Robin Schambach's user avatar
1 vote
Accepted

What's the attribute of a Matrix field to add error message

Matrix blocks are elements themselves, so the individual fields of a matrix block aren't available as properties on the entry. In the entry save hook, the only thing you can add errors to (that will ...
MoritzLost's user avatar
  • 11.9k
1 vote

What's the best practice for creating computed (dynamic/virtual) attributes on entries?

You can use behaviors to add new methods to system components. See the link above for documentation. A behavior is a class that extends yii\base\Behavior and is attached to a component using the ...
MoritzLost's user avatar
  • 11.9k
1 vote

Validating Date of Birth format from a form field value

Here's what I ended up doing. Despite having the format of DD/MM/YYYY on the front-end the Craft model actually stores the date in YYYY-MM-DD. Given the main the reason for wanting to perform server ...
James White's user avatar
  • 1,191

Only top scored, non community-wiki answers of a minimum length are eligible