19 votes
Accepted

How can my plugin generate a generic modal window in the Control Panel?

Create a div with whatever contents you want in the modal, and with a class "modal". Then create a new Garnish.Modal object with it: var $div = $('<div class="modal">...</div>'); var ...
user avatar
14 votes
Accepted

Link to an entry via Entries field type

Even if you set the limit to 1, Craft always returns an array of entries. So you need to add first() to access the first (and only) entry. {{ entry.buttonTargets.first() }} It you don't add a ...
user avatar
  • 35.8k
13 votes
Accepted

How can I add a RichText-Field to my plugin's CP-section?

To do this you'll need to take a few steps: Load the necessary resources which include the redactor.css and redactor.js file. And if you are using Craft's macros for your fields, the form macro file....
user avatar
  • 13.2k
12 votes
Accepted

Resource for setting up Craft CMS Fields

This is a brain dump of learning resources I can think of. There's the official documentation. Straight Up Craft has some great learning articles and tutorials. They also happen to have the most ...
user avatar
  • 66.4k
11 votes

How to add more options to the 'Restrict allowed file types' settings?

You can now set allowedFileExtensions and extraAllowedFileExtensions in your config file. The first will re-define the list of allowed files, where the latter will allow you to add additional file ...
user avatar
7 votes
Accepted

When creating a fieldtype how do I provide methods to be used in the templates?

Like plugins, fieldtypes can have their own settings as you're aware but while you can grab your plugin settings from pretty much anywhere, fieldtypes are a little more contextual. In any case, like @...
user avatar
  • 1,623
6 votes
Accepted

Custom Field Type with Multiple Values

You can do this simply by setting your field type’s defineContentAttribute() method to return AttributeType::Mixed, which will tell Craft to JSON-encode its value before storing it in the database. ...
user avatar
6 votes
Accepted

Can I have a textarea field which isn't rich text?

If what you want is a multi-line plain text field, then check the Allow line breaks checkbox for that field.
user avatar
6 votes
Accepted

Using ElementType as field type for plugin in what way do I provide my own data to the modal?

Ah, in that case you'll need to make your own ElementType. You should probably check out https://github.com/pixelandtonic/Events - that's meant to be a simple ElementType to serve as an entry point ...
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
Accepted

Can I set color fields by hex value

If you have created a Color Field the color selector dialogue uses your browsers built-in color selector. On Chrome and Firefox, you should see a dialogue like this: | | | If you click over to ...
user avatar
5 votes
Accepted

How to populate Category field form frontend form?

Couple things. First, I believe you need to add an extra set of brackets to the name attribute. The reason being that category fields (as well as all 'related' fieldTypes) store more than one element, ...
user avatar
5 votes
Accepted

Change field arrangement from the entries page

No, that's not possible with Craft at the moment (2.4). You'll have to use the Field Layout Designer from Settings -> Sections -> {Section} -> {Entry Type} to manage your fields and tabs. You could ...
user avatar
5 votes
Accepted

Link to Global Fields like you can with the entries fieldtype

Not directly. You could have a dropdown of all the global set handles (use Dynamic Fields Plugin if you don't want to maintain this dropdown manually), and then in your template fetch the global set ...
user avatar
5 votes

How to loop through matrix block fields and pull out handle and content?

I find accessing content like this pretty unintuitive, but I think you will need to use the Twig attribute method. Hopefully the below can help keep you moving in the right direction. I've ...
user avatar
  • 13.2k
5 votes

List of reserved field handles

For those wondering, here is the link to Craft 3 reserved words: https://github.com/craftcms/cms/blob/ae64588a4963b06a093636be6686345bd3a9bca8/src/base/Field.php#L190
user avatar
5 votes
Accepted

Which string identifiers for field types do exist?

I don't know if any enum exists (couldn't find it in source), but you could have a look at the contents of the craft/app/fieldtypes folder (and ignore BaseFieldtypes, DataModels and interfaces) to ...
user avatar
  • 6,288
5 votes
Accepted

How can I get the type of a field using Twig?

You can use the className function {% switch className(field) %} {% case 'craft\\fields\\PlainText' %} {% case 'craft\\fields\\Dropdown' %}
user avatar
4 votes
Accepted

Linking to Search Results

You can use either get (via a direct link) or post (via javascript) which can be accessed in your search template using [craft.request.getParam(name)][1], and then either display the template (if a ...
user avatar
4 votes
Accepted

Field type for selecting a section (channel / structure / single)?

You can do this with LJ DynamicFields. In the plugin docs is an example of how to create a dropdown that is a list of all sections.
user avatar
4 votes
Accepted

Is it possible to change the time increments in the Date/Time field?

Not currently, but it should probably be a setting on the field. Craft currently uses jquery.timepicker (in craft/app/resources/lib/jquery.timepicker/jquery.timepicker.js) and is just going with it's ...
user avatar
  • 66.4k
4 votes
Accepted

Default field values?

As far as I know, the only fields that allow defaults are those that extend the BaseOptionsFieldType, namely Dropdown, Multiselect, Checkboxes, and RadioButtons. You could change your lightswitch to ...
user avatar
4 votes
Accepted

Is this Garnish message bad? "Element was added to more than one selector"

That message comes from from Garnish.Select, when the same DOM element is associated with two separate Garnish.Select instances. The JS will log that message right before destroying the first Garnish....
user avatar
4 votes
Accepted

How to add more options to the 'Restrict allowed file types' settings?

Currently, no. The list you see there is the result of a function in IOHelper called getFileKinds. It just hands out an array of options. While I don't have a recommendation for making this work, I do ...
user avatar
4 votes
Accepted

Is there any way of distinguishing whether a Date field's "time" is set or not?

The values entered in Date/Time fields are always saved as Craft datetime objects. This means it doesn't matter if you configure it to show the date, the time or both, Craft always saves them the same....
user avatar
  • 35.8k
4 votes
Accepted

Found cool example of Header Globals what field type is used for this?

Looks to me like a matrix field with 1 block (Navigation) and two fields : Plain Text - Headline Table - 2 columns with headings Label (Single-line text) and URL (Single-line text) It's worth noting ...
user avatar
  • 1,818
4 votes
Accepted

Getting checkbox options for a new entry, without having an entry

You can pull the field directly using craft.fields: {% set myFieldOptions = craft.fields.getFieldbyHandle('myFieldOptions') %} The options will be available under the field's settings.options ...
user avatar
4 votes
Accepted

Is it possible to translate the name of a field in the CP?

Static text on the front-end and Craft CP translations are handled through your translation files. All you need to do is name your fields without the translate filter and make sure they have suitable ...
user avatar
  • 3,594
4 votes
Accepted

Get label from value in radio buttons list fieldtype

You could make a macro and use that as a "shortcut": {% macro optionLabel(fieldHandle, optionValue) %} {%- set field = craft.fields.getFieldbyHandle(fieldHandle) %} {%- for option in field....
user avatar
  • 35.8k
4 votes
Accepted

How do I store code in Craft

Store it in a plaintext field, then when you output it, do: {{ entry.myfield | raw }}
user avatar
  • 10.9k

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