Skip to main content
Share Your Experience: Take the 2024 Developer Survey
5 votes

How to create custom field type in Craft 3

In order to include a custom field type you first need to register your own module or plugin you can create the basic structure for both from pluginfactory.io and register them as you like. There is ...
Robin Schambach's user avatar
4 votes
Accepted

How to query entries by field values

There is a related to parameter you can use Entry::find() ->section($section) ->relatedTo(['targetElement' => $image->id, 'field' => 'galleryImages') ->all();
Robin Schambach's user avatar
4 votes
Accepted

Adding Columns to a table

With the supercool table maker you can create dynamic tables. Is this what you are looking for?
Robin Schambach's user avatar
4 votes
Accepted

Plugin Error: "Unable to find component class"

So what happened was I un-gitignored my Composer files so I could deploy them to another environment. Then I switched from that branch to a different branch with different Composer files. After I ...
kmgdev's user avatar
  • 1,199
4 votes
Accepted

Trouble finding the correct path to template in custom module and getting the "Unable to find the template" error

If this is a module and not a plugin, you might need to declare your base template directory in the Module's __construct using: Event::on(View::class, View::EVENT_REGISTER_CP_TEMPLATE_ROOTS, function ...
Oli's user avatar
  • 7,495
3 votes
Accepted

How can I make my custom FieldType show up in an element index?

To make it possible to select fields from a custom FieldType in the Customizable Element Indexes interface, your FieldType class needs to implement the IPreviewableFieldType interface, like this: ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

How can I specify what happens when someone calls my fieldtype without any further dot chains?

entry.myFieldHandle will return whatever the field type’s prepValue() function returns. If you always want that to be HTML, then prepValue() can just return the HTML as a string or \Twig_Markup ...
Brandon Kelly's user avatar
3 votes
Accepted

More than one field for a fieldtype plugin

Nope – a single field can only have a single column in the craft_content table. If you need your FieldType to save complex data, you have two options: The easiest approach – by far – is to simply ...
Mats Mikkel Rummelhoff's user avatar
3 votes
Accepted

Plugin fieldtype settings for ColumnType::LongText being inserted as varchar(255)

The Field Types defineSettings method defines the settings that get handled when you create the field. Those field settings get stored as json in the craft_fields.settings column when the field is ...
Ben Parizek's user avatar
  • 13.5k
3 votes
Accepted

Get field settings of custom field via ElementInterface

I found the solution the values are stored in $this: public function normalizeValue($value, ElementInterface $element = null) { $type = $this->type; $shops = $this->shop; ... ...
antdev's user avatar
  • 137
3 votes
Accepted

Can I change a user field with twig without using a form?

Yes, it's possible via the special Twig do tag, which basically enables you to call methods without returning (i.e. outputting) anything (which is what happens with nearly every other Twig expression)....
Mats Mikkel Rummelhoff's user avatar
2 votes

Using data within a mixed attribute type to query Craft entries dates

Just in case anyone else comes across this problem in the future I actually managed to figure it out myself. I created kept the fieldtype as a DateTime field and grabbed the date/time and the extra ...
wizzer711's user avatar
2 votes
Accepted

Retrieve entries on custom field date using ElementCriteriaModel

It seems like a syntax error, you did not set the date correctly. This should work $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->section = 'inspections'; ...
Robin Schambach's user avatar
2 votes

Retrieve entries on custom field date using ElementCriteriaModel

The Error was because $criteria->inspectionDate > '("now")'; This way you can't get today's date. You could try this: $date = new DateTime(); $formattedDate = $date->format(DateTime::...
hashtagerrors's user avatar
2 votes
Accepted

Use a custom field type in Matrix Blocks - Craft 3

I'm not sure what it has to do with a matrix - you can use every field normally and inside a matrix, there is no restriction - but I usually create a custom field type. You can see how to create ...
Robin Schambach's user avatar
2 votes

Adding Columns to a table

I used the method described here: "A User-Friendly Table Field" http://www.drivesimplicity.com/blog/a-user-friendly-table-field -- instruct the user to leave columns that he/she doesn't want blank and ...
userAW's user avatar
  • 176
2 votes

How do I prevent Twig from encoding HTML?

Not sure about model, but you can return raw, unescaped value from plugin variable like this: use craft\helpers\Template as TemplateHelper; class someClass { public function someFunction() { ...
Piotr Pogorzelski's user avatar
2 votes
Accepted

Plugin field-type not getting javascript variable?

Keep in mind Craft parses the html of your field, it won't be used directly, thus the ID of your field can't be "#"+startDateFieldHandleunless you ignored Crafts methods or modified it in another way. ...
Robin Schambach's user avatar
2 votes
Accepted

Unable to render a plugin template

Please read the docs (or this) about how to render plugin templates. It's all well explained there . You don't need to define src/templates but your plugin handle `plugin-handle/settings.html`
Robin Schambach's user avatar
2 votes
Accepted

Input Tags Template for my Custom FieldType

You could use Select2 to search in a select field $(document).ready(function() { $('.my-custom-awesome-select-class').select2(); }); All you need to do is to include the js file via asset ...
Robin Schambach's user avatar
2 votes

Assets metadata: Matrix required?

You could go for a lightweight content-builder. That would mean that you could and would create a matrix blocktype for each of your content elements i.e. one blocktype for image with all the metadata ...
Herra Jon's user avatar
2 votes
Accepted

Craft CMS 3 data structure advice for vehicle make, model, trim, year tagging

Goal: Filter documents by related vehicle characteristics. My first idea would be to create it as such: Create an assets volume where all your documents will be uploaded to. Create a vehicle ...
Tom De Smet's user avatar
  • 1,456
2 votes
Accepted

Structure Navigation with 3 possible Link Types using Nav tag

I am doing something similar in using a Structure for the main navigation. Below is what I have. Hope it helps! {% set menu = craft.entries.section('navMain').all() %} <ul> {% nav link in ...
Todd's user avatar
  • 284
2 votes
Accepted

How to build a custom fieldtype containing multiple nested groups of text and dropdown pairs?

First, from your field type’s inputHtml() method, make sure you’re passing the field instance to the template as a field variable, and the value as a value variable: protected function fieldHtml($...
Brandon Kelly's user avatar
2 votes
Accepted

Querying Globals from a Custom Field Type gives 502 Bad Gateaway

The answer below is mostly taken from Brandon Kelly's answer on Github which I suggest to read for more detailed information: https://github.com/craftcms/cms/issues/12847 The reason for the endless ...
Roman Sobkuliak's user avatar
1 vote

Custom Pluging Entries FieldType

You can use a Relation Field for each of your element types and include a custom js rule so if one of them has a value, the other one can't be selected. The more difficult way would be to extend the ...
Robin Schambach's user avatar
1 vote

How can I get entry id in field

It may depend on where in the request you need to access the element. If you need to access the element in a Field class on your Entry Edit page, the getInputHtml method may be useful: public ...
Ben Parizek's user avatar
  • 13.5k
1 vote
Accepted

What is $source and $sources in BaseRelationField?

In case of the element type Asset sources are the available volumes. In case of Category the available sources are the different groups. Sources for Entry are your sections, Tag have the different ...
Robin Schambach's user avatar
1 vote

Multiple Category Sources Field

Got there in the end and very simply through: use Craft; use craft\fields\BaseRelationField; use craft\elements\Category; class Categories extends BaseRelationField { public static function ...
Cole Henley's user avatar
  • 1,741
1 vote

Multiple Category Sources Field

Isnt this possible with the modifyCategorySources hook? -> https://docs.craftcms.com/v3/extend/updating-plugins.html#modifyentrysources-modifycategorysources-modifyassetsources-modifyusersources I'm ...
Gįëł Tėttëłæår's user avatar

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