11

You can add a config.php file in the root of your plugin's folder (craft/plugins/pluginhandle/config.php) that specifies the default values of your config items by returning an array of key value pairs for config settings and values. If a user wants to change any of those settings, they can add a pluginhandle.php config file to craft/config/pluginhandle.php ...


8

Whenever you output anything with Twig’s {{ output tags }}, the contents will get encoded by default. You have to pass the content through the |raw filter in order for it to be output verbatim. {{ entry.myFieldHandle|raw }}


8

See here for example front-end HTML code for all of Craft's default field types: https://straightupcraft.com/articles/craft-cms-field-guide-twig?view=input Matrix: {# You need to include the 'type' input to identify the matrix block type you are submitting #} <input type="hidden" name="fields[fieldHandle][new1][type]" value="contacts"> {# All of ...


6

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. public function defineContentAttribute() { return AttributeType::Mixed; } Then, whatever you submit in the field’s post data will be saved as-is. For ...


6

There is the Ace Freely plugin, which adds an Ace Editor Field Type that would work well in a Matrix field.


6

You can get the Element Select’s JS instance like so: $(document).ready(function() { var elementSelect = $('#your-container-id').data('elementSelect'); }); (Replace your-container-id with whatever ID you passed into the id param when calling forms.elementSelect or forms.elementSelectField.) Then you can attach a selection callback to that: ...


5

Here’s what your field type’s getInputHtml() method should look like: public function getInputHtml($name, $value) { // If $value['trial_end'] is set, make sure that it's a DateTime object if (!empty($value['trial_end'])) { $value['trial_end'] = DateTime::createFromString($value['trial_end']); } else { $value['...


5

As you discovered, you can get the current element that a field type is getting applied to via $this->element. However you must keep in mind that that property will not always be set. So make sure that your PHP/template code is defensive about the possibility that there is no known element yet. Another assumption to avoid is that the current element is ...


5

If anybody is interested, I created a simple unique text field plugin that extends the core text field: https://github.com/fuel-digital/Craft-Unique-Text-FieldType.


4

This will return the content for the specific element instance you're on: $this->element->getContent() And from there you can do your additional content processing. When you're ready so save it, you can call: craft()->content->saveContent($this->element); There are several examples in craft/app/fieldtypes folder where Craft's native field ...


4

Since craft/storage/ is not publicly accessible, your only real option here is to serve them through Craft as Resource Requests. (This is the vehicle through which Craft serves up all of the CP’s front end resources, which live in craft/app/resources/.) The actual resource URLs will depend on the site’s resourceTrigger config setting, so to generate the ...


4

Run your HTML string through getRaw before sending it back to the template... return TemplateHelper::getRaw($output); This will basically "pre-raw" your HTML string.


4

I came up with an answer, but be good to know if there is a better way of doing it: /** * Checks if another entry exists with the given reference * * @param string $value The reference to check * @return bool */ private function referenceExists($value) { $existing = craft()->elements->getCriteria(ElementType::Entry)->first(array( ...


4

You already mentioned the related answer in custom fieldtype with multiple values, and it actually is perfect for your usecase. It doesn't really matter how you transport the data over to Craft, because if the content is set to AttributeType::Mixed, then Craft will JSON encode/decode it when requested. So, to save your data, send over an array, like so: $...


4

Yii’s CUploadedFile class actually doesn’t support retrieving uploaded files that came from a file input whose name was “namespaced” (e.g. name="fields[handle]" rather than just name="handle"). However, Craft has its own UploadedFile class which extends CUploadedFile, and the whole point of it is to add that namespaced input name support. It uses a dot ...


4

On Straight up Craft we use a Doxter Block for Markdown and Rainbow.js with a custom Craft-Twig extension for syntax highlighting. Doxter allows you to identify the code block like so: ``` twig {{ siteUrl }} ``` or ``` php <?php echo "hello world"; ?> ``` And you can view the syntax in highlighting in the CP before you publish using Live Preview.


4

You should be using it like this: public function onAfterElementSave() { $fieldHandle = $this->model->handle; if ($this->element!==null) { $myData = $this->element->title; // just an example if ($this->element->$fieldHandle != $myData) { $this->element->getContent()->setAttribute($fieldHandle,...


4

The BaseFieldType class (which all FieldTypes extend) has a contentPostLocation property, which will give you the "path" to the field inside the entry model. The value is returned as a string, e.g. fields.myCustomFieldTypeHandle. If your field is inside a Matrix block, the contentPostLocation path will include the Matrix field's handle – as well as the ...


4

setContentFromPost() performs an operation on the attached ContentModel, not on the element model itself. When you initialize a BaseElementModel, its content attributes are set from the associated ContentModel. ("Content attributes" means attributes from custom field data, a.k.a. the stuff you'll typically find in the craft_content DB table for a given ...


4

With the supercool table maker you can create dynamic tables. Is this what you are looking for?


3

That string that Craft stores is just JSON. When you try to save an array, Craft will automatically JSON-encode it, since MySQL doesn’t have an array-based data type. To get that string to be automatically decoded back into an array for you, you need to give your field type a defineContentAttribute() method that returns AttributeType::Mixed: public ...


3

Completely untested, but a possibility would be to define your content attribute like so: return array(AttributeType::Mixed, 'model' => 'MyPluginContentModel'); MyPluginContentModel would have every possible value that you would want to expose to your template ('id', 'obj', 'etc') defined as an attribute. When Craft pulls the JSON from the database, it ...


3

Try this: public function getFunctions() { return array ( 'my_func' => new \Twig_SimpleFunction('my_func', array($this, 'my_func'), array('is_safe' => array('html'))) ); } This being the important part: array('is_safe' => array('html'))


3

Something like this (Let's call the fieldtype Geo): Your field html should output those two fields, and update a hidden input with the correct namespaced fieldname. Get it like this: $id = craft()->templates->formatInputId($name); $namespaceInputId = craft()->templates->namespaceInputId($id); See docs here about binding JS to fields. Your ...


3

Have a look at Iain Urquhart's plugin, Pointy: https://github.com/iainurquhart/Craft-Pointy It's a port of his EE addon that's similar to Entry Mapper, but I'm not 100% certain if it's production ready or not.


3

That’s a tricky one, because right now the {% cache %} tag is only focussed on the actual HTML that gets output between its tags, but when you include Javascript using TemplatesService::includeJs, etc., that’s actually queuing up the Javascript to be output later on. So, the trick here will be to make sure any JS that is included within the {% cache %} tag ...


3

Looks like the error is occurring when your field type’s getSearchKeywords() function is called. The value that’s passed into that function will have already been run through prepValue(), so at that point it looks like it will be a MyPlugin_MyModelNameModel instance (whatever the actual class name is). If your field type doesn’t override getSearchKeywords(),...


3

You could check if the whole request is Live Preview using craft.request.isLivePreview.


3

If your custom field needs more than the default column to store it's data you can create your own custom table (or tables) and store your data however you need to. This involves a few things: Create a Record that defines your database table Save the data to the custom table Retrieve the data from the custom table Create a Record that defines your ...


3

I would say you can do this yeah, it just take a little figuring out is all. Your input template could look something like: <input type="text" name="{{ name }}[title]" value="{{ value.title is defined ? value.title }}"> <input type="text" name="{{ name }}[description]" value="{{ value.description is defined ? value.description }}"> <input ...


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