function easy_social_preprocess_easy_social in Easy Social 8.4
Same name and namespace in other branches
- 8.3 easy_social.module \easy_social_preprocess_easy_social()
Implements hook_preprocess_HOOK() for easy_social theme.
See also
theme_easy_social()
File
- ./
easy_social.module, line 130 - Easy Social module.
Code
function easy_social_preprocess_easy_social(&$variables) {
$config = Drupal::config('easy_social.settings');
// Load widget definitions.
$definitions = easy_social_get_widgets();
//Add the CSS
$variables['#attached']['library'][] = 'easy_social/easysocial-css';
// Filter active widgets.
$settings_widgets = $config
->get('global.widgets');
$settings_widgets = array_filter($settings_widgets);
$widgets = array();
foreach ($settings_widgets as $widget) {
if (!array_key_exists($widget, $definitions)) {
throw new EasySocialException(t('No definition found for the widget: @name', array(
'@name' => $widget,
)));
// watchdog('easy_social', 'No definition found for widget: @widget', array('@widget' => $widget), WATCHDOG_ERROR);
}
// Handle css includes.
$attached = array();
if (array_key_exists('css', $definitions[$widget])) {
$attached['library'][] = $definitions[$widget]['css'];
}
// Determine how to handle js.
if (array_key_exists('js', $definitions[$widget])) {
$attached['library'][] = $definitions[$widget]['js'];
}
$widgets[$widget] = array(
'#theme' => "easy_social_{$widget}",
// @TODO pass in some kind of context?
// @TODO #weight ?,
'#attached' => $attached,
);
}
$variables['widgets'] = $widgets;
}