Questions tagged [attribute]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
155 views

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

I try to validate some fields before saving the entry, if the field is invalid, prevent the entry from saving and return the error message, I'm doing it via Element::EVENT_BEFORE_SAVE event. It works ...
Thomas's user avatar
  • 69
1 vote
1 answer
94 views

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

What is the best practice for defining an attribute on an Entry that isn't persistent? For example, I want to create a formatted string from two separate values stored in fields on the entry, but don'...
Tyler's user avatar
  • 11
3 votes
1 answer
36 views

Setting valueless boolean attributes with the tag function

When using the tag function, how does one handle valueless attributes which could also be null? For example, it's great we can do… {% set idVar = 'idstring' %} {% set nameVar = 'namestring' %} {% ...
Jonathan Schofield's user avatar
2 votes
2 answers
1k views

Add custom attribute to standard element from plugin

Developing plugin for Craft 3, I want to add extra property to Assets (data being pulled from other table) I am able to pull in the data by extending element query: Event::on( ...
Yuri Salimovskiy's user avatar
2 votes
1 answer
205 views

Model values assignment issue

I am setting attributes on my record using a models' attributes (that has validated successfully). I cannot figure out why the values aren't assigned. I can manually assign each one but that's ...
Shift2Design's user avatar
1 vote
0 answers
168 views

Table attributes not customisable for nested entry sources [closed]

Using a plugin, I have added some nested entry sources to some of the default section entry sources in my site. For example: 'section:6' => [ 'label' => 'News', ... 'nested' => [...
Tim Everts's user avatar
3 votes
1 answer
952 views

Model/Record AttributeType documentation?

I'm building a plugin which creates a few tables, and need to store some fairly robust data. I've done this before and previously gotten by with mostly AttributeType::String and AttributeType::Mixed, ...
Gavin Anderegg's user avatar
1 vote
2 answers
883 views

Validating Date of Birth format from a form field value

I'm working a on website project which includes a web form which asks for various personal details, one of the fields on the form is Date of Birth. The form is being validated by a custom plugin ...
James White's user avatar
  • 1,151
1 vote
0 answers
54 views

Change existing EntryModel custom attribute values [duplicate]

I am trying to change custom field values of a existing entry, but it won't save them in the database. It saves it on the model but the entry isn't persisted to the database. craft()->on('...
Jacob's user avatar
  • 282
1 vote
1 answer
279 views

Getting UTC DateTime from Model attributes

The AttributeType::DateTime in model attributes saves as UTC which is great, but upon getting that attribute I receive a Craft\DateTime object with my server timezone set for it, and thus the time ...
Gustavs's user avatar
  • 406
1 vote
1 answer
769 views

Update User "Field Type" for Entry in Plugin

I have a channel called "Groups", with a users field type called members for the entries. I need to be able to add/remove users to the members entry field via plugin. What I've tried is: // criteria ...
taylor's user avatar
  • 1,128
1 vote
1 answer
75 views

Accessing and Manipulating a Variable

Hopefully simple variable / concatenation question: What is the best way to retrieve the url of a specific asset the name of which should be concatenated from an asset field variable and a text string?...
kerns's user avatar
  • 33
1 vote
1 answer
255 views

Using $model->validate() with AttributeType::Url

I have a basic model defined: protected function defineAttributes() { return array( 'id' => array(AttributeType::String, 'required' => true), 'url' => ...
taylor's user avatar
  • 1,128
1 vote
1 answer
442 views

Add or extend attributes (table column) to fields table

I'm trying to find a way to extend the meta fields inside a custom field definition. To illustrate: I need a min_vis def_vis and max_vis column for each field (or anytime a new one is added). ...
Bill Columbia's user avatar
2 votes
1 answer
164 views

Accessing the attributes of an Asset field

Specifically looking at these attributes http://d.pr/i/1ilbr I can access Alt text by {{ entry.assetHandle.first().altText }} and similarly can do {{ entry.assetHandle.first().sourceUrl }} but Source ...
Steven Grant's user avatar
  • 1,855
5 votes
1 answer
818 views

What attribute type should I set in the record or model to create a TEXT type in the database?

I am having a problem with record and model attribute types. I have a frontend user form with some textfields which require a TEXT type field in the database to hold the data. So far I have tried ...
Lettie's user avatar
  • 2,033
1 vote
1 answer
450 views

Is there a good way of setting a model attribute to be an instance of another model?

I have an API call to make that needs a particular format of data shown below. The person and addresses attributes are currently set as Mixed AttributeTypes and I'll need to create a manual validation ...
Russ Back's user avatar
  • 1,503
1 vote
0 answers
159 views

Record - Mixed/String values will not be saved if attribute not required=true

I have defined string and mixed attributes for my Record/Model. 'titel' => array(AttributeType::String), 'lage' => array(AttributeType::Mixed, 'required' => true), If i try to save a record,...
phaetons's user avatar
  • 705
2 votes
1 answer
436 views

How do I validate an array model attribute against a set of possible values?

I have a need to set a property on a plugin Model that is an array of one or more valid values. I can see that I can use AttributeType::Enum and record and define a set of values but if I'm not ...
Russ Back's user avatar
  • 1,503
0 votes
1 answer
494 views

AttributeType::String is NULL in my database

I have create a plugin to save information from my form in the front-end. I can create a row with some data. Email and Number type work well but String is NULL Have you any idea ? my controller ...
theatus's user avatar
  • 37
3 votes
1 answer
1k views

How can I have a dynamic/virtual attribute AND have as an attribute of the Model?

Take the example of a model with a firstName and lastName. I know I can add a getFullName method to the model, and $model->fullName will run through the getter. However, I'd like the attribute to ...
Tim Kelty's user avatar
  • 3,081
6 votes
2 answers
191 views

Difference between using subscript syntax and "dot" syntax when accessing attributes of a variable or advantages of usage one of them

When to use {{ variable.property }} and when to use {{ variable['property'] }} Is there a difference between these methods of accessing attributes of a variable or advantages of using one of them?
nicael's user avatar
  • 2,382