Skip to content

Instantly share code, notes, and snippets.

@cmcintosh
Created July 6, 2016 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmcintosh/daab90a41db51175ac016400797494ec to your computer and use it in GitHub Desktop.
Save cmcintosh/daab90a41db51175ac016400797494ec to your computer and use it in GitHub Desktop.
Customize Fieldsets in Drupal 8
<?php
/**
* Implements hook_theme, see https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!theme.api.php/function/hook_theme/8.2.x
*/
function custom_fieldset_theme($existing, $type, $theme, $path) {
return array(
'my_fieldset' => array(
'template' => 'my_fieldset',
'path' => $path .'/templates',
'render element' => 'element'
)
);
}
/**
* This is the theme callback for the custom fieldset theme.
*/
function theme_my_fieldset(&$variables) {
// See http://www.drupalcontrib.org/api/drupal/drupal!core!includes!form.inc/function/theme_fieldset/8
}
<?php
/**
* {@inheritdoc}
*/
public function buildForm ($form, $formState) {
// First define our fieldset, and add a #theme tag to our element.
// See http://www.drupalcontrib.org/api/drupal/drupal!core!includes!form.inc/function/theme_fieldset/8
// for the default implementation.
$form['customFieldset'] = array(
'#type' => 'fieldset',
'#theme' => 'my_fieldset',
'#title' => t('My Custom Fieldset')
);
return $form;
}
// insert your custom html.
// You must clear cache after each change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment