If you run the following code:

$a = array(
  'whatever' => array(
    '#theme' => 'image',
    '#path' => 'some/random/path',
    '#title' => 'Some title',
    '#alt' => 'Some alt text',
    '#attributes' => array(
      'class' => 'some-class',
    ),
  ),
);
$r = $a;
debug(drupal_render($r));
$a['whatever']['#path'] = '/some/random/path';
$r = $a;
debug(drupal_render($r));
$a['whatever'] += array(
  '#absolute' => FALSE,
  '#query' => array(
    'a' => 'b',
  ),
);
$r = $a;
debug(drupal_render($r));

You get:

'<img class="some-class" typeof="foaf:Image" src="http://my-domain.local/some/random/path" alt="Some alt text" title="Some title" />'
'<img class="some-class" typeof="foaf:Image" src="/some/random/path" alt="Some alt text" title="Some title" />'
'<img class="some-class" typeof="foaf:Image" src="/some/random/path" alt="Some alt text" title="Some title" />'

I would expect "absolute" and "query" to be used to create the url, but they're not. Is there a way to pass these along to drupal_render()?

Comments

Jaypan’s picture

You cannot pass the query and absolute - they won't do anything. Instead, just qualify the full URL:

$a = array(
  'whatever' => array(
    '#theme' => 'image',
    '#path' => 'http://example.com/some/random/path?a=b',
    '#title' => 'Some title',
    '#alt' => 'Some alt text',
    '#attributes' => array(
      'class' => 'some-class',
    ),
  ),
);

Or if you want to do it dynamically you can do it with the url() function:

$a = array(
  'whatever' => array(
    '#theme' => 'image',
    '#path' => url('some/random/path', array('absolute' => TRUE, 'query' => array('a'=>'b'))),
    '#title' => 'Some title',
    '#alt' => 'Some alt text',
    '#attributes' => array(
      'class' => 'some-class',
    ),
  ),
);
alberto56’s picture

Thanks @Jaypan, much appreciated!