Answers.Body: <p>To get the URL of an asset in a plugin, you use a similar technique as you do in twig, so this will fetch the URL of the first image in the <code>blogImage</code> field:</p>
  
  <pre><code>$picture = $entry-&gt;blogImage-&gt;first()-&gt;url;
  </code></pre>
  
  <p>To answer you second question, <code>onBeforeSaveEntry</code> is run just before the entry is actually saved, not just before it is published live on the site if it has been saved with a post date in the future.</p>
  
  <p>Craft doesn't fire any events just before an entry becomes 'live' on the site, so if you want the post to Buffer to go out at the same time as the entry goes live using this technique, you will need to actually create and save the entry when you want to publish it live on your site.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-17T14:35:58.620Z
Answers.LastActivityDate: 2016-05-17T14:35:58.620Z
Answers.UserDisplayName: Steve Rowling
Body: <p>I'm trying to auto-post from my blog to Facebook using Buffer and this plugin (<a href="https://straightupcraft.com/craft-plugins/buffer" rel="nofollow">https://straightupcraft.com/craft-plugins/buffer</a>). The addon requires me to create a plugin to do the actual posting to Buffer. This is my first foray into plugins at all. I used his example and got something that works. </p>
  
  <p>However, the question I have is somewhat general. How do I pull an asset from an entry that has been saved to be able to post to the plugin? </p>
  
  <p>This is the relevant portion of the plugin:</p>
  
  <pre><code>$picture = craft()-&gt;request-&gt;getUrl($entry-&gt;blogImage);
  
  craft()-&gt;buffer_utils-&gt;queueBufferUpdate($updateString, true, $link, $picture, $thumbnail);
  </code></pre>
  
  <p>Obviously, my asset field name is <code>blogImage</code>.</p>
  
  <p>Also, and let me know if I need to create a new question for this, how does <code>onBeforeSaveEntry</code> affect scheduled content? Does/will the plugin run when it's actually saved or when it becomes "live"? If so, is there a workaround for that?</p>
  
  <p>Thanks.</p>
  
  <p>edit: I did reach out directly to the developer but have not had any luck yet and was hoping the question was general enough that someone else might be able to help!</p>
  
Tags: <assets><plugins>
Title: Pulling assets into a plugin
ThreadText: # Pulling assets into a plugin
  
  (Asked by: username_0 on 2016-05-17)
  
  I'm trying to auto-post from my blog to Facebook using Buffer and this plugin (<https://straightupcraft.com/craft-plugins/buffer>). The addon requires me to create a plugin to do the actual posting to Buffer. This is my first foray into plugins at all. I used his example and got something that works.
  
  However, the question I have is somewhat general. How do I pull an asset from an entry that has been saved to be able to post to the plugin?
  
  This is the relevant portion of the plugin:
  
  ```
  $picture = craft()->request->getUrl($entry->blogImage);
  
  craft()->buffer_utils->queueBufferUpdate($updateString, true, $link, $picture, $thumbnail);
  
  ```
  
  Obviously, my asset field name is `blogImage`.
  
  Also, and let me know if I need to create a new question for this, how does `onBeforeSaveEntry` affect scheduled content? Does/will the plugin run when it's actually saved or when it becomes "live"? If so, is there a workaround for that?
  
  Thanks.
  
  edit: I did reach out directly to the developer but have not had any luck yet and was hoping the question was general enough that someone else might be able to help!
  
  **Tags:** assets, plugins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-05-17. Score: 1
  
  To get the URL of an asset in a plugin, you use a similar technique as you do in twig, so this will fetch the URL of the first image in the `blogImage` field:
  
  ```
  $picture = $entry->blogImage->first()->url;
  
  ```
  
  To answer you second question, `onBeforeSaveEntry` is run just before the entry is actually saved, not just before it is published live on the site if it has been saved with a post date in the future.
  
  Craft doesn't fire any events just before an entry becomes 'live' on the site, so if you want the post to Buffer to go out at the same time as the entry goes live using this technique, you will need to actually create and save the entry when you want to publish it live on your site.
  
  
  ---
  
  