Created
July 30, 2013 21:43
-
-
Save bangpound/6117282 to your computer and use it in GitHub Desktop.
Render Drupal fields inside the rendered markup of other Drupal fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implement hook_file_view_alter(). | |
* | |
* @param type $build | |
* @param type $entity_type | |
*/ | |
function MODULE_file_view_alter(&$build, $entity_type) { | |
$qp = QueryPath::withHTML($build['field_caption']['0']['#markup']); | |
// Captures the contents of the last element of the caption. If there are multiple | |
// paragraphs, this is the last one. | |
$html = $qp->find(':root body')->children(':last-child')->innerHTML(); | |
// Append rendered author and publisher field. | |
$html .= render($build['field_author']); | |
$html .= render($build['field_publisher']); | |
// Replace the contents of the last element. | |
$qp->find(':root body')->children(':last-child')->html($html); | |
// Set the render markup to the new value. | |
$build['field_caption']['0']['#markup'] = $qp->find(':root body')->innerHTML(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment