You are here

fb_instant_articles.module in Facebook Instant Articles 8

File

fb_instant_articles.module
View source
<?php

/**
 * @file
 * Contains fb_instant_articles.module..
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Template\Attribute;

/**
 * Implements hook_help().
 */
function fb_instant_articles_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the fb_instant_articles module.
    case 'help.page.fb_instant_articles':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('FB Instant articles RSS feed generator for integration into the FB IA program') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_page_attachments_alter
 *
 * @param array $page
 *   page render array
 */
function fb_instant_articles_page_attachments_alter(array &$page) {

  /**
   * @var Drupal\Core\Config\ImmutableConfig $config
   *   The config entity for fb_instant_articles
   */
  $config = \Drupal::config('fb_instant_articles.adminconfig');
  if ($config instanceof Drupal\Core\Config\ImmutableConfig) {

    /**
     * If there is a stored configuration for the FIA Application ID
     * then add a page <meta> tag to all pages showing the id
     *
     * <meta property="fb:pages" content="{id goes here}" />
     */
    $fia_pagesid = $config
      ->get('pagesid');
    if ($fia_pagesid != '') {
      $meta_fia_pagesid = [
        '#tag' => 'meta',
        '#attributes' => [
          'property' => 'fb:pages',
          'content' => $fia_pagesid,
        ],
      ];
      $page['#attached']['html_head'][] = [
        $meta_fia_pagesid,
        'fia_pagesid',
      ];
    }
  }
}

/**
 * Prepares variables for views FIA item templates.
 *
 * Default template: views-view-row-fia.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - row: The raw results rows.
 */
function fb_instant_articles_preprocess_views_view_row_fia(&$variables) {
  $item = $variables['row'];
  $variables['attributes'] = new Attribute($item);
}

Functions

Namesort descending Description
fb_instant_articles_help Implements hook_help().
fb_instant_articles_page_attachments_alter Implements hook_page_attachments_alter
fb_instant_articles_preprocess_views_view_row_fia Prepares variables for views FIA item templates.