protected function ConverterBase::executeHook in Drupal 7 to 8/9 Module Upgrader 8
Executes the target module's implementation of the specified hook, and returns the result.
Return value
mixed
Throws
\LogicException if the target module doesn't implement the specified hook, or if the implementation contains logic.
6 calls to ConverterBase::executeHook()
- Blocks::convert in src/
Plugin/ DMU/ Converter/ Blocks.php - Performs required conversions.
- HookEntityInfo::convert in src/
Plugin/ DMU/ Converter/ HookEntityInfo.php - Performs required conversions.
- HookFieldFormatterInfo::convert in src/
Plugin/ DMU/ Converter/ HookFieldFormatterInfo.php - Performs required conversions.
- HookFieldWidgetInfo::convert in src/
Plugin/ DMU/ Converter/ HookFieldWidgetInfo.php - Performs required conversions.
- HookLibrary::convert in src/
Plugin/ DMU/ Converter/ HookLibrary.php - Performs required conversions.
File
- src/
ConverterBase.php, line 57
Class
- ConverterBase
- Base class for converters.
Namespace
Drupal\drupalmoduleupgraderCode
protected function executeHook(TargetInterface $target, $hook) {
$indexer = $target
->getIndexer('function');
if ($indexer
->has($hook)) {
// Configure the ContainsLogicFilter so that certain "safe" functions
// will pass it.
$has_logic = new ContainsLogicFilter();
$has_logic
->whitelist('t');
$has_logic
->whitelist('drupal_get_path');
$function = $indexer
->get($hook);
if ($function
->is($has_logic)) {
throw new \LogicException('{target}_{hook} cannot be executed because it contains logic.');
}
else {
$function_name = $function
->getName()
->getText();
if (!function_exists($function_name)) {
eval($function
->getText());
}
return call_user_func($function_name);
}
}
else {
throw new \LogicException('{target} does not implement hook_{hook}.');
}
}