jquery_matchheight_views-1.0.4/jquery_matchheight_views.module
jquery_matchheight_views.module
<?php
/**
* @file
* Primary module hooks for this module.
*/
/**
* Implements hook_element_info_alter().
*/
function jquery_matchheight_views_views_plugins_display_alter(array &$plugins) {
if (isset($plugins['page']['class'])) {
$plugins['page']['class'] = '\Drupal\jquery_matchheight_views\Plugin\views\display\Page';
}
if (isset($plugins['page']['class'])) {
$plugins['block']['class'] = '\Drupal\jquery_matchheight_views\Plugin\views\display\Block';
}
}
/**
* Implements hook_preprocess_views_view().
*/
function jquery_matchheight_views_preprocess_views_view(&$variables) {
$view = $variables['view'];
if ($view) {
$jquery_matchHeight = $view->display_handler->getOption('jquery_matchHeight');
if ($jquery_matchHeight && $jquery_matchHeight['enabled'] && $jquery_matchHeight['settings']) {
$class = 'view_jquery_matchheight_' . $variables['id'] . '_' . $variables['display_id'];
$settings = $jquery_matchHeight['settings'];
$rows = explode("\r\n", $settings);
$jquery_matchheight_views_settings = [];
foreach ($rows as $row) {
$items = explode('|', $row);
$config_key = ['selector', 'byRow', 'property', 'target', 'remove'];
$config = [];
foreach ($items as $item_key => $item) {
if (isset($config_key[$item_key]) && $config_key[$item_key] == 'selector') {
$config[$config_key[$item_key]] = '.' . $class . ' ' . $item;
}
elseif (isset($config_key[$item_key]) && $config_key[$item_key] !== 'selector') {
if (in_array($item, ['true', 'false'])) {
$config['options'][$config_key[$item_key]] = $item == 'true' ? TRUE : FALSE;
}
elseif ($item != 'null') {
$config['options'][$config_key[$item_key]] = $item;
}
}
}
$jquery_matchheight_views_settings[] = $config;
}
$variables['attributes']['class'][] = $class;
$variables['#attached']['library'][] = 'jquery_matchheight_views/jquery_matchheight_views.init';
$variables['#attached']['drupalSettings']['jquery_matchHeight'][$class] = $jquery_matchheight_views_settings;
}
}
}
