skype-8.x-1.2/skype.module

skype.module
<?php

/**
 * Holds hooks and general functionality.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function skype_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.skype':
      $output = file_get_contents(drupal_get_path('module', 'skype') . '/README.md');
      return '<pre>' . $output . '</pre>';
  }
}

/**
 * Implements hook_theme().
 */
function skype_theme() {
  return [
    'skype_button' => [
      'variables' => ['skype_id' => NULL, 'settings' => []],
      'template' => 'skype-button',
    ],
    'skype_uri' => [
      'variables' => ['skype_id' => NULL, 'settings' => []],
      'template' => 'skype-uri',
    ],
    'skype_chat_canvas' => [
      'variables' => [
        'message_recipient' => NULL,
        'chat_id' => NULL,
        'attributes' => [],
      ],
      'template' => 'skype-chat-canvas',
    ],
  ];
}

/**
 * Implements hook_page_attachments().
 */
function skype_page_attachments(array &$attachments) {
  /** @var \Drupal\skype\Manager\SkypeManager $manager */
  $manager = Drupal::service('skype.manager');

  if ($manager->loadSkypeChatCanvas()) {
    $attachments['#attached']['library'][] = 'skype/skype.chat.canvas';
  }
}

/**
 * Implements hook_page_bottom().
 */
function skype_page_bottom(array &$page_bottom) {
  /** @var \Drupal\skype\Manager\SkypeManager $manager */
  $manager = Drupal::service('skype.manager');

  if ($manager->loadSkypeChatCanvas()) {
    $page_bottom['skype'] = [
      '#theme' => 'skype_chat_canvas',
      '#message_recipient' => $manager->getMessageRecipient(),
      '#chat_id' => $manager->getChatId(),
      '#attributes' => $manager->getAttributes(),
    ];
  }

}

/**
 * Implements hook_preprocess_hook().
 */
function skype_preprocess_skype_button(&$variables) {
  $settings = $variables['settings'];

  $actions = array_filter($settings['actions']);
  $variables['skype_name'] = (count($actions) > 1) ? 'dropdown' : array_shift($actions);
  $variables['unique_id'] = uniqid();
  $variables['image_color'] = $settings['image_color'];
  $variables['image_size'] = $settings['image_size'];
}

/**
 * Implements hook_preprocess_hook().
 */
function skype_preprocess_skype_uri(&$variables) {
  $settings = $variables['settings'];

  $variables['link_text'] = str_replace('[skype:id]', $variables['skype_id'], $settings['link_text']);
  $variables['action'] = ($settings['action'] == 'video') ? 'call&video=true' : $settings['action'];

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc