visualn-8.x-1.x-dev/visualn.module
visualn.module
<?php
/**
* @file
* Contains visualn.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\visualn\Entity\VisualNStyle;
use Drupal\visualn\Entity\VisualNDrawer;
use Drupal\visualn\Entity\VisualNSetup;
use Drupal\Core\Template\Attribute;
use Drupal\views\ViewExecutable;
/**
* Implements hook_help().
*/
function visualn_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the visualn module.
case 'help.page.visualn':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Data visualization api') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function visualn_theme($existing, $type, $theme, $path) {
return [
'visualn_drawer_preview_form' => [
'render element' => 'children',
'template' => 'forms/visualn-drawer-preview-form',
],
'visualn_drawing_build_wrapper' => [
'variables' => [
'build' => NULL,
'html_selector' => '',
],
'template' => 'visualn-drawer-build-wrapper',
],
];
}
/**
* Implements hook_form_alter().
*/
function visualn_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'visualn_style_add_form') {
// check if query parameter set for using session stored values
$uuid = \Drupal::request()->query->get('drawer-preview');
if (!empty($uuid)) {
$tempstore = \Drupal::service('tempstore.private')->get('visualn_drawer_preview');
$style_data = $tempstore->get($uuid, '');
if (!empty($style_data)) {
$base_drawer_id = $style_data['drawer_id'];
$drawer_config = $style_data['drawer_config'];
if (!empty($base_drawer_id)) {
$prefixed_id = 'base|' . $base_drawer_id;
$form['drawer_id']['#default_value'] = $prefixed_id;
// stored_configuration is used in VisualN Style form to set values back to ones
// stored in visualn style config when changing drawer
// @see \Drupal\visualn\Form\VisualNStyleForm.php
$form['drawer_container']['#stored_configuration']['prefixed_id'] = $prefixed_id;
$form['drawer_container']['#stored_configuration']['drawer_config'] = $drawer_config;
}
}
}
}
}
/**
* Gets an array of image styles suitable for using as select list options.
*
* @param $include_empty
* If TRUE a '- None -' option will be inserted in the options array.
* @return
* Array of image styles both key and value are set to style name.
*/
function visualn_style_options($include_empty = TRUE) {
$styles = VisualNStyle::loadMultiple();
$options = array();
if ($include_empty && !empty($styles)) {
$options[''] = t('- None -');
}
foreach ($styles as $name => $style) {
$options[$name] = $style->label();
}
if (empty($options)) {
$options[''] = t('No defined styles');
}
return $options;
}
function visualn_subdrawer_options($include_empty = TRUE) {
$subdrawers = VisualNDrawer::loadMultiple();
$options = array();
if ($include_empty && !empty($subdrawers)) {
$options[''] = t('- None -');
}
foreach ($subdrawers as $name => $subdrawer) {
$options[$name] = $subdrawer->label();
}
if (empty($options)) {
$options[''] = t('No defined subdrawers');
}
return $options;
}
function visualn_setup_options($include_empty = TRUE) {
$setups = VisualNSetup::loadMultiple();
$options = array();
if ($include_empty && !empty($setups)) {
$options[''] = t('- None -');
}
foreach ($setups as $name => $setup) {
$options[$name] = $setup->label();
}
if (empty($options)) {
$options[''] = t('No defined setups');
}
return $options;
}
/**
* Implements hook_visualn_raw_resource_format_info_alter().
*/
function visualn_visualn_raw_resource_format_info_alter(&$definitions) {
// @todo: Temporarily add all plugins to "defaut" group. This should
// be set in each specific plugin annotation.
foreach ($definitions as $k => $definition) {
$definitions[$k]['groups'][] = 'default';
}
}
