Hi everyone,

I am developing a custom Drupal module and I need to pass data dynamically from one module to another. For example, Module A generates some user-related data, and Module B needs to use it for custom processing.

Here’s a simplified scenario:

// Module A
function module_a_generate_data($uid) {
$user = \Drupal\user\Entity\User::load($uid);
return [
'username' => $user->getAccountName(),
'roles' => $user->getRoles(),
];
}

// Module B
function module_b_process_data($data) {
// Process user data
\Drupal::logger('module_b')->notice('Username: @name', ['@name' => $data['username']]);
}

The challenge i want a clean maintainable way for Module B to always get updated data from Module A without directly calling functions in a tightly coupled way.

Are there other recommended patterns for safely sharing data between modules? 

Comments

jaypan’s picture

What is the actual use case of what you want to do? It's a bit too generalized right now to give a solution. 

Contact me to contract me for D7 -> D10/11 migrations.