Linked Questions

6
votes
3answers
2k views

setContent() vs $entry->getContent()->foo

I'm a bit confused about the usage of these two. Let's say I want to create a new entry from a controller. For me, the nicer option would be to user something like this: $entry = new EntryModel(); $...
7
votes
3answers
2k views

Getting all content, including Matrix fields from an EntryModel

Initially I was doing $entry->getContent()->getAttributes(), but noticed my Matrix fields were all null. What is the right way to do this? I see that $entry->myMatrixField gives me the ...
5
votes
1answer
734 views

How to set a field of an asset from within a plugin

I am using the following code to save an asset that has been downloaded to the storage/runtime/temp directory from an external API $response = craft()->assets->insertFileByLocalPath( $...
3
votes
1answer
605 views

Is there a way to set a new property on an entry

In a plugin I am creating I want to add a property to some entries. Ideally this property would be hidden from the admin user, as I don't want them to edit it. At the moment I am trying to do ...
2
votes
2answers
666 views

How to save a global set’s content?

I’m trying to set data within a global set. I’ve tried the following without success: $globalSetHandle = 'settings'; $globalSet = craft()->globals->getSetByHandle($globalSetHandle); $globalSet-...
0
votes
1answer
837 views

Accessing custom fields from User Model

I have a User entries field called 'company'. I'm writing a bespoke plugin to manage users in the front-end and was wondering how I can access the content of this field in my plugin via the user model?...
3
votes
1answer
772 views

How do you add tags to tag field when saving an entry?

I'm working on a custom import plugin which needs to import a load of content to fields including categories and tags. Categories is working fine using a comma separated list of category ids: ...
1
vote
1answer
741 views

Update User Profile with Plugin

I'm trying to create a plugin to create/update users' profile data. I figured out how to create a user but updating... not so much. Here is the code I'm using: $user = craft()->userSession->...
2
votes
1answer
487 views

Can someone help me identify why my entry is invalidating?

I have a custom plugin that's saving an entry successfully. While saving the entry I'm setting our "merchant" field (an entries field, limit=1) like so: <?php # ... $entry = newEntryModel(); # set ...
3
votes
1answer
232 views

Set Entries field in Commerce order on completion

I'm trying to set an Entries field within a Commerce Order once the order completes. I've tried using the onOrderComplete event like so; craft()->on('commerce_orders.onOrderComplete',function($...
1
vote
2answers
490 views

onBeforeSaveEntry listener to add/modify data of some fields

I'm trying to build my first, very simple, one file plugin. I'm having difficulty with a basic task and I can't find any documentation to help me out. Keep in mind that there is no validation ...
4
votes
1answer
290 views

Updating just a single content field from a plugin

I have a Task that is running through a collection of elements, moving some data from one field to another. The problem I am hitting (more and more with situations like this) is that in order to ...
2
votes
1answer
337 views

How to duplicate an element type model with content?

Duplicating models is easy if you do it from the edit view, where you can just omit the ID and pass it along to save(). But how would I go about doing that programmatically without having a POST ...
3
votes
1answer
172 views

Why does field value get updated on $element->getContent()->fieldHandle but not when accessed directly $element->fieldHandle?

I am trying to update a custom field on an EntryModel. I'm having half success, and I don't understand why. I've looked at other posts such as this one by Brandon which discuss how to assign these ...
2
votes
1answer
335 views

How do I programmatically set a Users company field?

I'm currently able to add a user with the following code (from the Docs): $user = new UserModel(); $user->username = 'tommy'; $user->firstName = 'Tom'; $user->lastName = 'Foolery'; $user-&...

15 30 50 per page