13 votes
Accepted

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

You should be using setContentFromPost() rather than setContent(), so that field types have a chance to prep the values that you are passing in. See “What is getContent() / the ContentModel, and how ...
user avatar
8 votes

Tech Support-Provider for Craft CMS

This is Leslie, I'm the Chief Customer Officer for Craft CMS. I'm not sure I can help, but I'd like to know more. Specifically I'm not sure I can source a dev shop in Germany, but I may be able to get ...
user avatar
6 votes
Accepted

How to tell if user exists

Something like this should work: public function add($user) { $existingUser = craft()->users->getUserByUsernameOrEmail($user->username); if ($existingUser) { // They ...
user avatar
  • 66.4k
6 votes

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

I am just iterating on the previous answer to attempt to explain why this is happening. If you take a look at BaseElementModel.php at the setContent() method. You'll see that the core code is doing ...
user avatar
5 votes
Accepted

Service not defined

Looks like a casing issue to me. You should be calling: craft()->campaignReports_campaignMonitor->getSettings();
user avatar
4 votes

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

Have you tried using that form of setting with this method instead? $entry->setContentFromPost(['foo' => 'bar', 'xyz' => '123']); There's also this method: $entry->getContent()->...
user avatar
4 votes
Accepted

Plugin Settings: Attribute Types, and how to receive

As far as accessing the value of the setting, try: $plugin = craft()->plugins->getPlugin('pluginHandle'); $plugin->getSettings()->getAttribute('pluginSettings1'); If you need to access ...
user avatar
4 votes
Accepted

How to catch errors in a service and return to a controller?

There are several ways you could go about this. One that I tend to prefer is to go ahead and have your controller grab whatever data it needs from POST and populate a Model with it. That model is ...
user avatar
  • 66.4k
4 votes
Accepted

How do I call a service from my controller in a plugin?

Try it with a lowercase f in the middle... craft()->fulcrumDonation_fulcrumCyberSource->exampleService();
user avatar
  • 23.6k
4 votes
Accepted

Craft 3: how to call methods in another plugin's service?

Assuming Plugin1 is their main plugin class file name, you could do: \fully\qualified\namespace\Plugin1::getInstance()->myService->myMethod(); In order for this to work: Craft must be ...
user avatar
  • 66.4k
3 votes
Accepted

Craft 3: How to get Volume by handle?

As of this commit, there is a Craft::$app->getVolumes()->getVolumeByHandle($handle) method you can call.
user avatar
  • 66.4k
3 votes
Accepted

Using Services to get all the Categories related to an Entry?

If you have an EntryModel and know the category field's handle, you don't really need a service: $categories = $entry->categoryFieldHandle; In other cases, you can construct an ...
user avatar
3 votes
Accepted

saveEntry() not firing

Something on the $entryToSave EntryModel is failing validation. If you echo out implode(', ', $entryToSave()->getAllErrors());, then you'll see what those errors are and you can correct them.
user avatar
  • 66.4k
3 votes

MVC - Should these be seperate controllers/models etc

Well, it looks like Sprout Forms itself prefers separate services for everything (they'd be some big services if they weren't,) but Craft does bundle closely-related things together sometimes - ...
user avatar
  • 4,361
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

Whats the best way to save a new entry in my plugin?

You can use the FrontEnd Entry Form for this. If you want to allow guests (non-registered users) to submit the form, you need to use the Guest Entries plugin. Both methods will set "publishing date, ...
user avatar
  • 8,316
3 votes
Accepted

Is it possible to access a Craft service directly from a Twig template?

The methods check if either ImageMagick and/or GD are installed and have been compiled with support for the respective format. If they return true, you can create transforms using these formats safely....
user avatar
  • 5,985
2 votes

Populate a record with a model?

Yii's setAttributes method is probably a better way to do this than the populateRecords method, as by default assignments will only be made to safe attributes. See this wiki article, Understanding "...
user avatar
  • 6,136
2 votes
Accepted

Populate a record with a model?

Yii does have the equivalent populateRecord and populateRecords on CActiveRecord. However, on both the populateModel(s) and populateRecord(s) methods, you should be very cautious of blindly mass-...
user avatar
  • 66.4k
2 votes
Accepted

How can I use a session consistently in a service and variable?

I suspect you're getting different session IDs because you're creating a new instance of HttpSessionService (which ultimately is a wrapper for PHP's session handling). What you should be doing is ...
user avatar
  • 66.4k
2 votes
Accepted

Error when calling methods between two services (triggered by init)

Your service’s init() function gets called immediately after it is loaded – and before Yii has had a chance to remember that craft()->myPlugin should return the service instance. Take a look at ...
user avatar
2 votes
Accepted

Using services/records etc in migrations

Are there technical reasons for this recommendation, or is it something you'd just rather not support? It's more along the lines of it's something you're not going to want to support. The problem is ...
user avatar
  • 66.4k
2 votes

Issues with Twig template includes when rendering from a service called from a CP-triggered event

Not 100% sure what is going wrong here, but here is what I would do to debug this on my end: Simply output the current path the template parser is using in the controller and event handler to see the ...
user avatar
2 votes
Accepted

Craft plugin services in subfolders

Craft will only look in the immediate pluginHandle/services folder when auto-loading and registering a plugin's service files. If you wanted to support services in subfolders (i.e. pluginhandle/...
user avatar
  • 66.4k
2 votes

Need a way to connect to a webservice

Craft 2.x includes Guzzle 3 natively, so you could write a Craft plugin that uses it to consume your web service. There are plenty of examples in the Guzzle 3 docs on how to do that (as well as in ...
user avatar
  • 66.4k
2 votes
Accepted

Listen to onSetStatus event

As you've discovered, you should be using the more generic elements.onBeforePerformAction or elements.onPerformAction events. They get fired when any action takes place and you can check their action ...
user avatar
  • 66.4k
2 votes
Accepted

Migrating Server - Craft isn't installed yet

Have you tried running ./craft setup to double check if your setup is correct? If ./craft setup completes successfully ./craft should find the existing installation and complete any required setup. ...
user avatar
1 vote
Accepted

Changing asset of entry's assetfield via entries.onBeforeSaveEntry

After taking a look again, it turned out to simply be an issue with the scope of the array and a therefore empty array as a result. Works as expected now.
user avatar
1 vote

Loading dynamically-named classes in a plugin's service

Rather than assuming that the providers will live in a specific location, I'd be inclined to implement a custom hook, which allows third party plugins to register a new provider. This also allows ...
user avatar
1 vote

How to handle entry save in plugin when entryId is not set?

Had to browse through your plugin repo for a bit to try and wrap my head around what's going on, but I think you have the problem nailed down in that the issue is this: https://github.com/iNalgiev/...
user avatar
  • 66.4k

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