You are here

function thunder_fia_preprocess_node in Thunder 8.2

Same name and namespace in other branches
  1. 8.3 modules/thunder_article/modules/thunder_fia/thunder_fia.module \thunder_fia_preprocess_node()

Implements hook_preprocess_node().

File

modules/thunder_article/modules/thunder_fia/thunder_fia.module, line 75
Thunder Article module hooks.

Code

function thunder_fia_preprocess_node(&$variables) {

  /*
   * @var string $view_mode
   *  the view mode name
   */
  $view_mode = $variables['view_mode'] = $variables['elements']['#view_mode'];
  if ($view_mode == 'fb_instant_articles_rss') {

    /*
     * If we are looking at a node using the fia rss view-mode, then only show
     * field values for entities that are also in an fia view mode
     */
    if (is_array($variables['content'])) {
      foreach ($variables['content'] as $key => $content) {
        if (isset($content['#theme']) && $content['#theme'] == 'field') {
          foreach (Element::children($content) as $index) {
            $value = $content[$index];
            if (empty($value['#view_mode'])) {
              continue;
            }
            switch ($value['#view_mode']) {
              case 'facebook_instant_articles_rss':
                break;
              default:
                $variables['content'][$key][$index]['#access'] = FALSE;
            }
          }
        }
      }

      // If first paragraph is the teaser image, don't render it.
      if (thunder_fia_get_first_paragraph_image_entity($variables['node'])) {
        $variables['content']['field_paragraphs'][0]['#access'] = FALSE;
      }
    }
  }
}