wetboew_webform_example-1.0.x-dev/wetboew_webform_example.module
wetboew_webform_example.module
<?php use Drupal\Core\Form\FormStateInterface; /** * @file * Primary module hooks for WetBoew Webform Example module. * */ /** * Implements hook_theme_suggestions_HOOK_alter(). * @inheritdoc */ function wetboew_webform_example_theme_suggestions_form_element_label_alter(array &$suggestions, array $variables, $hook) { // if (isset($variables['element']['#id'])) { // $suggestions[] = $hook . '__' . $variables['element']['#id']; // } $suggestions[] = $hook . '__wetboew'; return $suggestions; } /** * Implements hook_theme_suggestions_HOOK_alter(). * @inheritdoc */ function wetboew_webform_example_theme_suggestions_fieldset_alter(array &$suggestions, array $variables, $hook) { $suggestions[] = $hook . '__wetboew'; return $suggestions; } /** * Implements hook_form_alter() to add css asset. */ function wetboew_webform_example_form_alter(&$form, FormStateInterface $form_state, $form_id) { $current_path = \Drupal::service('path.current')->getPath(); if (strpos($current_path, 'admin') <= -1) { if (strpos($form_id, 'wetboew') !== FALSE) { $form['#attached']['library'][] = 'wetboew_webform_example/small.tweaks'; } } } /** * Implements hook_theme(). */ function wetboew_webform_example_theme() { return [ 'form_element_label__wetboew' => [ 'template' => 'form-element-label--wetboew', 'base hook' => 'form_element_label', ], 'fieldset__wetboew' => [ 'template' => 'fieldset--wetboew', 'base hook' => 'fieldset', ], ]; } /** * Implements hook_theme_registry_alter(). */ function wetboew_webform_example_theme_registry_alter(&$theme_registry) { if (isset($theme_registry['form_element_label__wetboew']['path'])) { if (stripos($theme_registry['form_element_label__wetboew']['path'], 'label') <= 0) { // Tell the theming system to look in this modules templates/label folder for the twig file. $theme_registry['form_element_label__wetboew']['path'] = $theme_registry['form_element_label__wetboew']['path'] . '/label'; } } if (isset($theme_registry['fieldset__wetboew']['path'])) { if (stripos($theme_registry['fieldset__wetboew']['path'], 'ieldset') <= 0) { // Tell the theming system to look in this modules templates/fieldset folder for the twig file. $theme_registry['fieldset__wetboew']['path'] = $theme_registry['fieldset__wetboew']['path'] . '/fieldset'; } } }