What's the correct way to execute code from an existing custom module at Drupal startup? The code checks certain private_tempstore values and sets other values based on what it finds. It should be executed before page processing occurs so that pages can respond to the changed values.
I've read many posts, looked through the list of hooks, tried a few without success, looked at event subscribing, etc. All my searching and trying hasn't found an approach that works correctly for my situation.
Example custom code (not the real code):
$rsc = \Drupal::service('user.private_tempstore')->get('rsc');
$val = $rsc->get('temp_val');
if ($val == 100) {
$rsc->set('temp_val', 200);
}
What I've tried:
hook_page_build() // in mymodule.module
hook_page_alter() // in mymodule.module
path: '/*' // in mymodule.routing.yml
No error messages, just no results via an error_log() in the custom code to show that it was executed.