Post

1 follower Follow
1
Avatar

Example of Create/Update with Embed Field Type?

I've been digging around thru the API.  Does anyone have a PHP example of how to use the Embed field type with a URL? I've been using PodioItem:create/insert a lot lately, and love the simplicity. I assume I'm going to need to create a PodioEmbed object and then reference the embed_id?

Thank you, Jeff

 

Jeff Walters Answered

Please sign in to leave a comment.

8 comments

0
Avatar

Yep, you have it right. Something like this:

// This assumes that you have a PodioItem object in the $item variable.

// If you're editing an existing item PodioItem::get() will return such an object

// otherwise you can create one from scratch. See items.php in the examples folder

$attributes = array( 'url' => 'http://www.example.com' );

$embed = PodioEmbed::create( $attributes );

$item->field('my-embed-field')->set_value($embed);

$item->save();

Andreas Haugstrup Pedersen 0 votes
0
Avatar

If you needed to set multiple PodioEmbed objects, can you pass an array of PodioEmbed objects to the set_value() method? Such as:

$attributes1 = array( 'url' => 'http://www.example1.com' );

$embed1 = PodioEmbed::create( $attributes1 );

$attributes2 = array( 'url' => 'http://www.example2.com' );

$embed2 = PodioEmbed::create( $attributes2 );

$item->field('my-embed-field')->set_value(array($embed1, $embed2));

$item->save();

Or is there a way to add another PodioEmbed object to an existing list of PodioEmbed objects, so your not removing someones existing entries?

 

Jeff Walters 0 votes
0
Avatar

Help!  I just can't seem to figure out how to set the field properly. It just won't set. I've successfully created the PodioEmbed Object, and it looks great. I can var_dump it (PHP) and see the URL, title, and Images saved to cloudfront.net. They are very "LARGE" image files (jpeg's). I'm not sure if that would cause problems. The thumbnail doesn't seem to be of thumbnail size; it's full size.

My code seems to fail with the set_value() method.

$item->field('link')->set_value($embed);

I've also tried the array approach.

$attributes = array();

$attributes['url'] = $embed_url;

$embed = PodioEmbed::create(array('url' => $embed_url));

$attributes['embed']['embed_id'] = $embed->embed_id;

$attributes['file']['file_id'] = $embed->files[0]->file_id;

var_dump($embed);

$item->field('link')->set_value($attributes);

$item->save();

According to the App the field name is 'link'. Is this a reserved name perhaps?

Thank you,

Jeff

 

Jeff Walters 0 votes
0
Avatar

Apparently the field need to be created first. This just seems strange to me. If I've created the Item already, I'd expect the field to be ready to be set.

My external_id of the field is named 'link', see below. Once I used the PodioEmbedItemField class to create the field, I could then pass the PodioEmbed object to the set_value() method.

I'd love to see this be able to handle an array of objects.

 

$embed = PodioEmbed::create(array('url' => $embed_url));

$link_field = new PodioEmbedItemField('link');

$item->add_field($link_field);

$item->field('link')->set_value($embed);

$item->save();

 

Jeff Walters 0 votes
0
Avatar

Hi Jeff,

When you get an item via PodioItem::get() only the fields that have values are present. If you are setting the value of a new field you need to create the field object yourself. Some apps have a large amount of fields and it's much simpler to consume these items if they don't contain a large amount of empty fields.

If you're creating a PodioItem object from scratch ($item = new PodioItem()) it will have no fields by default and you need to create them manually. To prefill such an item would require an API call (to get the app structure) and podio-php will never make API behind your back. :)

Can't it take an array of embed objects? This should work:

$embeds = array(

PodioEmbed::create(array('url' => 'http://example.com/')),

PodioEmbed::create(array('url' => 'http://anotherexample.com/'))

);

$link_field = new PodioEmbedItemField('link');

$link_field->set_value($embeds);

$item->add_field($link_field);

$item->save();

Andreas Haugstrup Pedersen 0 votes
0
Avatar

Ah, yes, it does work. I must have had the same field issue at the time of testing - or some other problem. The example above with two embed objects does work. Thanks Andreas, your help here is much appreciated!

Jeff Walters 0 votes
0
Avatar

I have had code that creates an embed as described above and yesterday it just seemed to stop working, not sure why... the return from the PodioEmbed::create command is not returning an object is seems to be coming back as null.

Here is my code:

$attributes = array( 'url' => $organizationURL );

$embed = PodioEmbed::create( $attributes );

And I have verified that in this example $organizationURL is set to "http://www.infranet.com"

What would cause this?

Patrick

 

Patrick Steil 0 votes
0
Avatar

Nevermind... figured it out... BTW, you can get this condition if your Authentication isn't working properly... :)

Patrick Steil 0 votes