thierry-b
10/28/2013 - 8:42 AM

Strip certain html from news teaser and remove sharelinks from certain pages.

Strip certain html from news teaser and remove sharelinks from certain pages.

<?php
/**
 * Implements template_preprocess_node().
 **/
function template_preprocess_node(&$variables) {
  if($variables['type'] == 'news' && $variables['teaser']) {
    $images = element_children($variables['content']['image']);
    foreach ($images as $key => $image) {
      if($key !== 0) {
        unset($variables['content']['image'][$key]);
      }
    }
    $bodies = element_children($variables['content']['body']);
    foreach ($bodies as $key => $body) {
      $variables['content']['body'][$key]['#markup'] = "<p>" . strip_tags(str_replace("</p>", "<br>", $variables['content']['body'][$key]['#markup']), "<br>") . "</p>";
    }
  }

  // remove the sharelinks from certain basic pages
  if($variables['type'] == 'page') {
    $node = $variables['node'];
    $paths = array('contact', 'nieuws', 'home');
    if(in_array(drupal_get_path_alias(current_path()), $paths)) {
      unset($variables['content']['sharelinks']);
    }
  }
}