You are here

facebook_comments_block.module in Facebook Comments Block 8

File

facebook_comments_block.module
View source
<?php

/**
 * @file
 * facebook_comments_block.module
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function facebook_comments_block_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.facebook_comments_block':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('This module allows users to comment using Facebook\'s commenting box with as little configuration as possible. It adds a new block "Facebook Comments" which acts as a Facebook commenting widget.') . '</p>';
      $output .= '<h3>' . t('Configuration') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('You can place a facebook comment block in a region by selecting <em>Place block</em> on the <a href=":blocks">Block layout page</a>.', array(
        ':blocks' => \Drupal::url('block.admin_display'),
      )) . '</dt>';
      $output .= '<dt>' . t('Under the "FACEBOOK COMMENTS BOX SETTINGS" you can configure the following.') . '</dt>';
      $output .= '<dd>' . t('Facebook Application ID: (Optional).') . '</dd>';
      $output .= '<dd>' . t('Main domain: (Optional) If you have more than one domain you can set the main domain for facebook comments box to use the same commenting widget across all other domains.') . '</dd>';
      $output .= '<dd>' . t('Language: Select the default language of the comments plugin.') . '</dd>';
      $output .= '<dd>' . t('Color Scheme: Set the color schema of facebook comments box.') . '</dd>';
      $output .= '<dd>' . t('Order of comments: Set the order of comments.') . '</dd>';
      $output .= '<dd>' . t('Number of posts: Select how many posts you want to display by default.') . '</dd>';
      $output .= '<dd>' . t('Width: Set width of facebook comments box.') . '</dd>';
      $output .= '</dl>';
      $output .= '<h3>' . t('Troubleshooting') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('If the block did not appear:') . '</dt>';
      $output .= '<dd>' . t("check if you have entered a correct FACEBOOK APP ID, leave it blank in case you don't have a Facebook app.") . '</a></dd>';
      $output .= '</dl>';
      return $output;
  }
}

/**
 * Implements hook_theme().
 */
function facebook_comments_block_theme($existing, $type, $theme, $path) {
  return array(
    'facebook_comments_block_block' => array(
      'variables' => array(
        'data_attributes' => NULL,
      ),
      'template' => 'block--facebook-comments-block',
    ),
  );
}

/**
 * Implements hook_page_attachments().
 */
function facebook_comments_block_page_attachments(array &$page) {
  $config = \Drupal::config('block.block.facebookcommentsblock');
  $facebook_app_id = $config
    ->get('settings')['facebook_comments_block_settings_app_id'];
  $facebook_app_id_meta = array(
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'fb:app_id',
      'content' => $facebook_app_id,
    ),
  );
  $page['#attached']['html_head'][] = [
    $facebook_app_id_meta,
    'facebook_app_id_meta',
  ];
}