field_group_label_classes-8.x-1.2/field_group_label_classes.module
field_group_label_classes.module
<?php
/**
* @file
* Extend HTML fieldgroup render with title class.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function field_group_label_classes_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.field_group_label_classes':
$text = file_get_contents(dirname(__FILE__) . '/README.md');
if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
return '<pre>' . $text . '</pre>';
}
else {
// Use the Markdown filter to render the README.
$filter_manager = \Drupal::service('plugin.manager.filter');
$settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
$config = ['settings' => $settings];
$filter = $filter_manager->createInstance('markdown', $config);
return $filter->process($text, 'en');
}
}
return NULL;
}
/**
* Implements hook_theme_registry_alter().
*/
function field_group_label_classes_theme_registry_alter(&$theme_registry) {
$theme_registry['field_group_html_element']['path'] = \Drupal::service('extension.list.module')->getPath('field_group_label_classes') . '/templates';
}
/**
* Implements hook_preprocess_HOOK().
*/
function field_group_label_classes_preprocess_field_group_html_element(&$variables) {
$element = $variables['element'];
$variables['title_classes'] = [];
if (!empty($element['#title_classes'])) {
$variables['title_classes'] = explode(' ', $element['#title_classes']);
}
if (!empty($element['#effect']) && $element['#effect'] !== 'none') {
$variables['title_classes'][] = 'field-group-toggler';
}
$variables['title_classes'] = implode(' ', $variables['title_classes']);
}
