file alter.inc

Modify structured content arrays.

These hooks are called after the content has been assembled in a structured array and may be used for doing processing which requires that the complete content structure has been built.

If the theme wishes to act on the rendered HTML of the content rather than the structured content array, it may use this hook to add a #post_render callback. Alternatively, it could also implement hook_preprocess_HOOK().

File

includes/alter.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Modify structured content arrays.
  5. *
  6. * These hooks are called after the content has been assembled in a structured
  7. * array and may be used for doing processing which requires that the complete
  8. * content structure has been built.
  9. *
  10. * If the theme wishes to act on the rendered HTML of the content rather than
  11. * the structured content array, it may use this hook to add a #post_render
  12. * callback. Alternatively, it could also implement hook_preprocess_HOOK().
  13. *
  14. * @see \Drupal\Core\Render\RendererInterface
  15. * @see \Drupal\Core\Render\Renderer
  16. */
  17. use Drupal\block\Entity\Block;
  18. use Drupal\Core\Form\FormStateInterface;
  19. /**
  20. * Implements hook_form_FORM_ID_alter() for Drupal\search\Form\SearchPageForm.
  21. */
  22. function uikit_form_search_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  23. // SearchPageForm assigns a class to the help link as a string instead of an
  24. // an array. Let's fix that first.
  25. if (!is_array($form['help_link']['#options']['attributes']['class'])) {
  26. $help_link_classes = explode(' ', $form['help_link']['#options']['attributes']['class']);
  27. $form['help_link']['#options']['attributes']['class'] = $help_link_classes;
  28. }
  29. // Now add some classes to the help link for better spacing below the search
  30. // input.
  31. $form['help_link']['#options']['attributes']['class'][] = 'uk-display-inline-block';
  32. $form['help_link']['#options']['attributes']['class'][] = 'uk-margin-small-top';
  33. }
  34. /**
  35. * Implements hook_theme_suggestions_HOOK_alter() for block templates.
  36. */
  37. function uikit_theme_suggestions_block_alter(array &$suggestions, array $variables) {
  38. $base_plugin_id = $variables['elements']['#base_plugin_id'];
  39. $id = $variables['elements']['#id'];
  40. $block = Block::load($id);
  41. $region = $block->get('region');
  42. // Add block__REGION to theme suggestions.
  43. $suggestions[] = 'block__' . $region;
  44. // Add block__REGION__menu to system menu blocks and block__navbar__item to
  45. // non-system menu and non-system branding blocks.
  46. $system_branding_block = $base_plugin_id == 'system_branding_block';
  47. $system_menu_block = $base_plugin_id == 'system_menu_block';
  48. if ($system_menu_block) {
  49. $suggestions[] = 'block__' . $region . '__menu';
  50. }
  51. elseif ($region == 'navbar' && !$system_branding_block) {
  52. $suggestions[] = 'block__navbar__item';
  53. }
  54. }
  55. /**
  56. * Implements hook_theme_suggestions_HOOK_alter() for container templates.
  57. */
  58. function uikit_theme_suggestions_container_alter(array &$suggestions, array $variables) {
  59. if (isset($variables['element']['administration_menu'])) {
  60. $suggestions[] = 'container__admin__toolbar';
  61. }
  62. }
  63. /**
  64. * Implements hook_theme_suggestions_HOOK_alter() for details templates.
  65. */
  66. function uikit_theme_suggestions_details_alter(array &$suggestions, array $variables) {
  67. if (isset($variables['element']['#group']) && $variables['element']['#group']) {
  68. $suggestions[] = 'details__grouped';
  69. }
  70. }
  71. /**
  72. * Implements hook_theme_suggestions_HOOK_alter() for form element templates.
  73. */
  74. function uikit_theme_suggestions_form_element_alter(array &$suggestions, array $variables) {
  75. $type = $variables['element']['#type'];
  76. // Add suggestions with the element type.
  77. $suggestions[] = 'form_element__' . $type;
  78. // Add suggestions for checkbox and radios to style advanced form elements.
  79. $form_advanced = $type == 'checkbox' || $type == 'radio';
  80. if ($form_advanced) {
  81. $suggestions[] = 'form_element__' . 'advanced';
  82. }
  83. }
  84. /**
  85. * Implements hook_theme_suggestions_HOOK_alter() for input templates.
  86. */
  87. function uikit_theme_suggestions_input_alter(array &$suggestions, array $variables) {
  88. if ($variables['element']['#type'] == 'entity_autocomplete') {
  89. $suggestions[] = 'input__autocomplete';
  90. }
  91. }

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Log in