With the help of Clive's comment, I managed to identify the active theme suggestion. Code below.
function mymodule_preprocess_field(&$variables, $hook) {
$theme_suggestions = mymodule_get_theme_suggestions($hook, $variables);
$active_suggestion = mymodule_get_active_theme_suggestion($theme_suggestions);
}
function mymodule_get_theme_suggestions(String $base_hook, array $variables) {
// Invoke hook_theme_suggestions_HOOK().
$suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_' . $base_hook, [$variables]);
// Invoke hook_theme_suggestions_alter().
$hooks = [
'theme_suggestions',
'theme_suggestions_' . $base_hook,
];
\Drupal::moduleHandler()->alter($hooks, $suggestions, $variables, $base_hook);
array_unshift($suggestions, $base_hook);
return $suggestions;
}
function mymodule_get_active_theme_suggestion($suggestions) {
$theme_registry = theme_get_registry(FALSE);
// Order by most specific first.
$suggestions = array_reverse($suggestions);
foreach ($suggestions as $candidate) {
if ($theme_registry
->has($candidate)) {
return $candidate;
}
}
}
ThemeManager::render()
.