Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: PHP notice when attempting to create entry via EE’s Channel Entries API

Status Resolved
Add-on / Version Publisher 1.0.5
Severity Trivial
EE Version 2.6.1

JohnDWells

Aug 19, 2013

Hi Brian,

We’re developing a module that allows entries to be created via an ACT endpoint - sort of like a SAEF form, but we can’t control the originating $_POST key/value pairs, so we’re handling the submission ourselves. The basic idea is to map the submitted keys to the correct field IDs, and then use EE’s channel API to create the entry.

And it largely seems to work so far, however the following PHP notice is thrown from Publisher:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Publisher_lib::$publisher_save_status
Filename: hooks/Publisher_relationship_hooks.php
Line Number: 114

I’m gathering from the source that Publisher_lib::$publisher_save_status is supposed to be set from $_POST[‘publisher_save_status’], which doesn’t exist in the originating $_POST array.  I’ve tried manually setting it, but this seems to have no effect. If I just hard code it straight onto ee()->publisher_lib, then it works. But the question is, is that best?

Here’s the gist of the working code:

ee()->load->library('api');
ee()->api->instantiate('channel_entries');
ee()->api->instantiate('channel_fields');

// handle Publisher
if(array_key_exists('publisher', ee()->addons->get_installed('modules')))
{
  // add to $_POST array (this does not help)
  $_POST['publisher_save_status'] = 'open';

  ee()->load->library('Publisher/Publisher_lib');
  ee()->load->library('Publisher/Publisher_api_channel_fields', NULL, 'api_channel_fields');

  // brute force (this helps)
  ee()->publisher_lib->publisher_save_status = 'open';
}

// act as admin
ee()->session->userdata['group_id'] = 1;

// take what we get from $_POST, and morph it to be well-formed for ee()->api_channel_entries->submit_new_entry()
$data = $this->prepare_entry();

// set up entry settings (no idea what this does, but things break if absent)
ee()->api_channel_fields->setup_entry_settings($this->channel_id, $data);

// submit a new entry
ee()->api_channel_entries->submit_new_entry($this->channel_id, $data);

// return errors if present
if(count(ee()->api_channel_entries->errors) > 0)
{
  return ee()->api_channel_entries->errors;
}

// horray!
return ee()->api_channel_entries->entry_id;

Any insights or hints are appreciated.

Cheers,
John

#1

BoldMinded (Brian)

I would just go with the forceful option. There isn’t anything wrong with that approach b/c there isn’t much logic behind setting that property… it just takes the post value anyway.

#2

JohnDWells

Thanks Brian, we’ll forge ahead with this. So far so good…

Cheers, John

Login to reply