tipsy.module in Tipsy 8
Same filename and directory in other branches
Main file for Tipsy module.
File
tipsy.moduleView source
<?php
/**
* @file
* Main file for Tipsy module.
*/
use Drupal\Core\Render\Element;
/**
* Implements hook_theme().
*/
function tipsy_theme() {
$form = \Drupal::formBuilder()
->getForm('Drupal\\tipsy\\Form\\AdminSettingsForm')['custom_selectors'];
return array(
'tipsy_custom_selectors_form' => array(
'variables' => [
'form' => $form,
],
'function' => 'theme_tipsy_custom_selectors_form',
'#cache' => [
'max-age' => 0,
],
),
);
}
/**
* Theme the table form for tipsy rules.
*/
function theme_tipsy_custom_selectors_form($variables) {
$form = $variables['form'];
$rows = array();
$headers = array(
t('Selectors'),
t('Options'),
);
foreach (Element::children($form) as $key) {
$row = array(
'data' => array(
array(
'data' => render($form[$key]['selector']),
),
array(
'data' => render($form[$key]['options']),
),
),
);
$rows[] = $row;
}
$output = [];
$output[] = [
'#theme' => 'table',
'#header' => $headers,
'#rows' => $rows,
'#cache' => [
'max-age' => 0,
],
];
return render($output);
}
/**
* Helper function to retreive all settings for tipsy.
*/
function _tipsy_get_settings($new_rule = FALSE) {
if ($new_rule == TRUE) {
$settings = \Drupal::configFactory()
->getEditable('tipsy.settings')
->get('new_rule_settings');
}
else {
$settings = \Drupal::configFactory()
->getEditable('tipsy.settings')
->get('wide_settings');
}
return $settings;
}
/**
* Implements hook_page_attachments().
*/
function tipsy_page_attachments(array &$attachments) {
$settings = _tipsy_get_settings();
if ($settings['drupal_forms']['forms'] == 0) {
unset($settings['drupal_forms']);
}
$settings = \Drupal::configFactory()
->getEditable('tipsy.settings')
->get("wide_settings");
$attachments['#attached']['library'][] = 'tipsy/tipsy';
$attachments['#attached']['drupalSettings']['tipsy'] = $settings;
}
Functions
Name | Description |
---|---|
theme_tipsy_custom_selectors_form | Theme the table form for tipsy rules. |
tipsy_page_attachments | Implements hook_page_attachments(). |
tipsy_theme | Implements hook_theme(). |
_tipsy_get_settings | Helper function to retreive all settings for tipsy. |