Answers.Body: <p>Assuming you already have the entry (see <a href="http://buildwithcraft.com/docs/plugins/working-with-elements" rel="noreferrer">Working with Elements</a> for info about how to do that), you can interact with it exactly the same way you do in your templates - just with PHP syntax instead of Twig.</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>$asset = $entry-&gt;thumbnail-&gt;first();
  
  if ($asset)
  {
      $url = $asset-&gt;getUrl('thumb');
  }
  </code></pre>
  
  <p>Though the transform won’t necessarily be available yet, since getUrl() will not generate transforms that don’t already exist by default. </p>
  
  <p>That behavior can be customized with the <a href="http://buildwithcraft.com/docs/config-settings#generateTransformsBeforePageLoad" rel="noreferrer">generateTransformsBeforePageLoad</a> config setting though, and lucky for you, you can even override the actual config value from PHP before calling getUrl(), using <a href="http://buildwithcraft.com/classreference/services/ConfigService#set-detail" rel="noreferrer">ConfigService::set()</a>:</p>
  
  <pre class="lang-php prettyprint-override"><code>craft()-&gt;config-&gt;set('generateTransformsBeforePageLoad', true);
  $url = $asset-&gt;getUrl('thumb');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-22T15:33:18.323Z
Answers.LastActivityDate: 2014-08-22T15:33:18.323Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I've got an asset field on a channel entry called "thumbnail". I'm using it to return a singular image, specifically for an image transform called "thumb". Looks a little like this:</p>
  
  <pre><code>{{ entry.thumbnail.first().getUrl('thumb') }}
  </code></pre>
  
  <p>This works fine. But I'd like to get the same information/url using a plugin (so I can perform some colour validation and other checks via PHP). </p>
  
  <p>Can anyone share some wisdom on how best to approach this please?</p>
  
Tags: <plugin-development><assets>
Title: Get entry field data via a plugin. ( For specific image assets )
ThreadText: # Get entry field data via a plugin. ( For specific image assets )
  
  (Asked by: username_0 on 2014-08-22)
  
  I've got an asset field on a channel entry called "thumbnail". I'm using it to return a singular image, specifically for an image transform called "thumb". Looks a little like this:
  
  ```
  {{ entry.thumbnail.first().getUrl('thumb') }}
  
  ```
  
  This works fine. But I'd like to get the same information/url using a plugin (so I can perform some colour validation and other checks via PHP).
  
  Can anyone share some wisdom on how best to approach this please?
  
  **Tags:** plugin-development, assets
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-08-22. Score: 8 | Accepted answer
  
  Assuming you already have the entry (see [Working with Elements](http://buildwithcraft.com/docs/plugins/working-with-elements) for info about how to do that), you can interact with it exactly the same way you do in your templates - just with PHP syntax instead of Twig.
  
  ```php
  $asset = $entry->thumbnail->first();
  
  if ($asset)
  {
      $url = $asset->getUrl('thumb');
  }
  
  ```
  
  Though the transform won’t necessarily be available yet, since getUrl() will not generate transforms that don’t already exist by default.
  
  That behavior can be customized with the [generateTransformsBeforePageLoad](http://buildwithcraft.com/docs/config-settings#generateTransformsBeforePageLoad) config setting though, and lucky for you, you can even override the actual config value from PHP before calling getUrl(), using [ConfigService::set()](http://buildwithcraft.com/classreference/services/ConfigService#set-detail):
  
  ```php
  craft()->config->set('generateTransformsBeforePageLoad', true);
  $url = $asset->getUrl('thumb');
  
  ```
  
  
  ---
  
  