18 votes
Accepted

What is getContent() / the ContentModel, and how do I use it to get and set custom field values?

BaseElementModel::getContent() will return the element’s ContentModel. It has two purposes: To store the element’s data from the craft_content table table when fetching elements from the DB. To store ...
user avatar
14 votes
Accepted

Is it possible to use the ElementType Modal UI for a custom Field Type Plugin?

Yep, you can do that with Craft.createElementSelectorModal(): var myModal = Craft.createElementSelectorModal('Entry', { resizable: true, storageKey: 'someUniqueID', ...
user avatar
12 votes
Accepted

Best way to implement my own statuses on my custom element type?

All you need to return from the getStatuses() method is an associative array() where the key represents the status name and the value represents the status label, more or less. An example might be a ...
user avatar
  • 1,623
12 votes
Accepted

How do I return ALL entries that are singles

There's no such method available for craft.entries, at least it's not documented. But you can use craft.sections to get an array of section models and filter them with a conditional within a loop: {# ...
user avatar
  • 35.8k
10 votes

How to make use of Element Types

Element Types are powerful and there are probably too many possible implementations to give a very meaningful example without additional information. Here are a couple resources beyond the docs that ...
user avatar
  • 13.2k
6 votes

Display thumbnail using defineTableAttributes for a custom Element Type

Ok, so I've managed to get an answer to this courtesy of Brandon Kelly. It's much more simple than I thought. Firstly, you do not have to specify a relatedTo parameter the defineCriteriaAttributes()....
user avatar
  • 121
6 votes
Accepted

Is it possible to use the field layout designer in settings screen?

There are two ways to retrieve field layouts: by ID (FieldsService::getLayoutById()) and by element type (FieldsService::getLayoutByType()). The former is useful for element types that manage multiple ...
user avatar
6 votes
Accepted

How can you return elements between two values?

You’re close! You just need to begin the array with "and": $criteria = craft()->elements->getCriteria(ElementType::User); $criteria->customNumberField = array('and', '>=5', '<=10'); $...
user avatar
6 votes
Accepted

In my element type index view, why is the first column always empty?

The first column is reserved for whatever your element model's __toString() function returns. By default that is the element's title, if your element type has editable titles. Otherwise you will need ...
user avatar
6 votes
Accepted

How do I add a value to a tag field type using the entries service saveEntry method?

The Tags field classifiedTags needs an array of tag IDs, not slugs/titles. Also, if this is an existing entry and you want to retain tags already added to the field, you'll need to pull the existing ...
user avatar
5 votes

Where exactly are my element type custom statuses stored and used?

For starters I'd classify statuses in two groups - static statuses and dynamic statuses: Static statuses are set explicitly Dynamic statuses change according to other circumstances (other attribute ...
user avatar
5 votes

How do I stop an element from populating?

I am not really clear on what you are trying to do. My guess is you are trying to add your own validation to saving an element and trying to block that with your own custom checking of content values ...
user avatar
  • 6,637
5 votes
Accepted

Why does a Element Criteria Model Query with Strings on a custom element type not filtering?

Found the answer, simple mistake. if ($criteria->code) { $query->andWhere(DbHelper::parseParam('trips.code', $criteria->code, $query->params)); } was needed along with public ...
user avatar
5 votes

Change custom element Index title via getTableAttributeHtml?

I finally found the answer to this question. From BaseElementType defineAvailableTableAttributes() docs, The first item that this array returns will just identify the database column name, and ...
user avatar
  • 356
5 votes
Accepted

ElementType CP section does not display table

You haven't defined any sources for your ElementType. <?php public function getSources($context = null) { $sources = [ '*' => [ 'label' => Craft::t('All entries'), ...
user avatar
  • 2,947
4 votes
Accepted

How would I trigger updateElements for BaseElementIndex from a plugin's JavaScript?

The cleanest way to do this would be to provide your own Javascript class that overrides Craft.BaseElementIndex, which stores the latest search value in localStorage: MyElementTypeIndex = Craft....
user avatar
4 votes

How to integrate custom statuses in a workflow style custom element type?

I looked into this a little bit... It looks like the color of the circles is dependent on one of these CSS classes by default: .status.live - Green .status.pending - Orange .status.expired - Red ....
user avatar
  • 23.6k
4 votes
Accepted

How would I setup my plugin to use a unique fieldlayout that is unique to the top level of the plugin?

You're bumping into this error because of a minor misunderstanding of how Pixel & Tonic are referencing their Element Types. The problem you have is with this line of code: $fieldLayout->type =...
user avatar
  • 23.6k
4 votes
Accepted

Where exactly are my element type custom statuses stored and used?

Short answer: Your custom statuses will be stored in your own 3rd party table. Based on everything you've mentioned in this thread, it sounds like you've figured out how to at least define your ...
user avatar
  • 23.6k
4 votes
Accepted

Use a custom Element Type without sources?

Element Types, Custom Fields, and Sources can work closely together, but how you structure that relationship has a lot of flexibility. Sources are optional. They are a convenient way to group and ...
user avatar
  • 13.2k
4 votes
Accepted

Filtering list in CP index page for new ElementType

In case anyone else comes up against this, here's what I did to fix it. In my PluginName_MyElementType class which inherits from BaseElementType, you need to override the defineSearchableAttributes ...
user avatar
4 votes
Accepted

Split-style button for "New" custom element

Those split-style buttons are just multiple regular buttons (.btn) next to each other, wrapped in a .btngroup div: <div class="btngroup submit"> <a class="btn submit" href="#">Button ...
user avatar
4 votes

How to check an elements elementType

Having arrived here from a Google search while trying to do this in Twig rather than PHP, I thought it might help someone in future to leave an answer, even though it doesn't address your question ...
user avatar
  • 3,794
3 votes
Accepted

Change title url of elementtype in the list

I found the solution of this was under my nose, I added this public function populateElementModel($row){ $model = Plugin_ClientModel::populateModel($row); return $model; } In ...
user avatar
  • 427
3 votes
Accepted

Create Plugin, Elementtype suggestion

You likely won't need to write a plugin at all – you can easily create different user groups (e.g. "Workers" and "Clients") from the Control Panel, and grant those groups different permissions. An ...
user avatar
3 votes
Accepted

Allow anonymous submission on a custom element type?

Ok, so I finally figured it out. The trick was using the following two methods: assembleLayoutFromPost() setContentFromPost('fields') The controller now looks like this: public function ...
user avatar
3 votes

Why does my custom element type error around locale being missing on the element types' model?

That's interesting Luke, I had the exact same issue and spent WAY too long on it. Even though I used a diff tool to see the difference between working elementType models and the one with the error I ...
user avatar
  • 6,637
3 votes
Accepted

Is it possible for an Element Type to return multiple content tables with the getContentTableForElementsQuery() method?

You can only return a single content table per element query. If you need to join multiple content tables, you have two options: Use multiple element queries, one for each group of elements that ...
user avatar
3 votes
Accepted

How to integrate custom statuses in a workflow style custom element type?

Here is a quick code summary of how this can be done. // GasTankElementType public function hasStatuses() { return true; } public function getStatuses() { return array( 'full' => ...
user avatar
  • 1,623
3 votes

How to trigger updateElements when hide modal?

If the page is rendered from a template that extends _layouts/elementindex, then the Element Index class instance is available at Craft.elementIndex. So all you’d need to do is include this in the ...
user avatar

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