Skip to content

Instantly share code, notes, and snippets.

@slivorezka
Created November 28, 2016 11:08
Show Gist options
  • Save slivorezka/76e9f5255432ced981f58771bb6cf15e to your computer and use it in GitHub Desktop.
Save slivorezka/76e9f5255432ced981f58771bb6cf15e to your computer and use it in GitHub Desktop.
Drupal 8: Allow other modules to alter your data
<?php
// Allow other modules to alter your data.
$data = [
'#type' => 'markup',
'#markup' => t('This is the default text.'),
];
\Drupal::moduleHandler()->alter('MODULE_some_action', $data);
/**
* Implements hook_MODULE_some_action_alter().
*/
function MODULE_MODULE_some_action1_alter(&$data) {
// Here we have full access to $data array.
$data['#markup'] = t('This was altered by MODULE.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment