Drupal 8 Hooks hook_element_info_alter()

There are many hooks in drupal 8

So i will list the most important hooks which i have used so far

hook_element_info_alter()

Alter the element type information returned from modules.

A module may implement this hook in order to alter the element type defaults defined by a module.

example code:

function hook_element_info_alter(&$type) {
  // Decrease the default size of textfields.
  if (isset($type['textfield']['#size'])) {
    $type['textfield']['#size'] = 40;
  }
}

function mymodule_element_info_alter(array &$types) {
  //call the custom function after build.
  foreach ($types as $type => $info) {
    $types[$type]['#after_build'][] = 'my_custom_function';
  }
}

This hook is mainly used to alter the elements so $type contains all the elements.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s