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 ...
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,...
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[] = ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
attribute × 23plugin-development × 11
models × 10
records × 4
craft3 × 2
plugins × 2
datetime × 2
events × 2
entrymodel × 2
templating × 1
assets × 1
users × 1
database × 1
entry × 1
form × 1
field × 1
error-message × 1
fieldtypes × 1
variable × 1
entries-field × 1
validation × 1
assetfilemodel × 1
plugin-guestentries × 1
element × 1
table × 1