open_readspeaker.module in Open ReadSpeaker 8
Same filename and directory in other branches
Contains open_readspeaker.module.
File
open_readspeaker.moduleView source
<?php
/**
* @file
* Contains open_readspeaker.module.
*/
use Drupal\Core\Render\BubbleableMetadata;
/**
* Implements hook_theme().
*/
function open_readspeaker_theme($existing, $type, $theme, $path) {
return array(
'open_readspeaker_ui' => array(
'variables' => array(
'accountid' => NULL,
'open_readspeaker_i18n' => NULL,
'open_readspeaker_reading_area' => NULL,
'open_readspeaker_reading_area_class' => NULL,
'custom_style' => NULL,
'button_text' => NULL,
'button_title' => NULL,
'request_path' => NULL,
),
'template' => 'open_readspeaker_ui',
),
);
}
/**
* Implements hook_library_info_build().
*/
function open_readspeaker_library_info_build() {
$libraries = [];
$config = Drupal::config('open_readspeaker.settings');
$libraryUrl = $config
->get('open_readspeaker_url');
if (empty($libraryUrl)) {
$logger = \Drupal::logger('open_readspeaker');
$logger
->notice('ReadSpeaker URL can not be empty. Please add in Open ReadSpeaker configuration');
return $libraries;
}
$libraryTokenized = Drupal::token()
->replace($libraryUrl);
$libraries['basic'] = [
'version' => '1.0.x',
'js' => [
$libraryTokenized => [
'type' => 'external',
'minified' => TRUE,
],
],
'dependencies' => [
'core/jquery',
'core/drupalSettings',
],
];
return $libraries;
}
/**
* Implements hook_token_info().
*/
function open_readspeaker_token_info() {
$info = [];
$info['types'] = [
'open-readspeaker' => [
'name' => t('Open ReakSpeaker'),
'description' => t('Tokens related to the Open ReadSpeaker module.'),
],
];
$info['tokens'] = [
'open-readspeaker' => [
'account-id' => [
'name' => t('Account ID'),
'description' => t('The account ID of your ReadSpeaker account.'),
],
],
];
return $info;
}
/**
* Implements hook_tokens().
*/
function open_readspeaker_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$replacements = [];
if ($type === 'open-readspeaker') {
foreach ($tokens as $name => $original) {
switch ($name) {
case 'account-id':
$replacements[$original] = Drupal::config('open_readspeaker.settings')
->get('open_readspeaker_accountid');
break;
}
}
}
return $replacements;
}
Functions
Name | Description |
---|---|
open_readspeaker_library_info_build | Implements hook_library_info_build(). |
open_readspeaker_theme | Implements hook_theme(). |
open_readspeaker_tokens | Implements hook_tokens(). |
open_readspeaker_token_info | Implements hook_token_info(). |