Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By alberto56 on
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
D7? D8?
You cannot pass the query and absolute - they won't do anything. Instead, just qualify the full URL:
Or if you want to do it dynamically you can do it with the url() function:
Thanks @Jaypan, much
Thanks @Jaypan, much appreciated!