private function FetchEntityVariableAction::fetchEntity in Business Rules 8
Same name and namespace in other branches
- 2.x src/Plugin/BusinessRulesAction/FetchEntityVariableAction.php \Drupal\business_rules\Plugin\BusinessRulesAction\FetchEntityVariableAction::fetchEntity()
Fetch the entity.
Parameters
string $id: The entity id.
\Drupal\business_rules\VariableObject $variable: The VariableObject.
string $id_field: The field id.
\Drupal\business_rules\Entity\Action $action: The Business rule Action action.
string $bundle: The bundle.
mixed $original_variable_value: The original variable value.
Return value
\Drupal\Core\Entity\EntityInterface|null The entity.
1 call to FetchEntityVariableAction::fetchEntity()
- FetchEntityVariableAction::fetchEntityVariable in src/
Plugin/ BusinessRulesAction/ FetchEntityVariableAction.php
File
- src/
Plugin/ BusinessRulesAction/ FetchEntityVariableAction.php, line 260
Class
- FetchEntityVariableAction
- Class FetchEntityVariable.
Namespace
Drupal\business_rules\Plugin\BusinessRulesActionCode
private function fetchEntity($id, VariableObject $variable, $id_field, Action $action, $bundle, $original_variable_value) {
try {
$var = Variable::load($variable
->getId());
if ($var) {
$entity_type = $var
->getTargetEntityType();
$entity = \Drupal::entityTypeManager()
->getStorage($entity_type)
->load($id);
if (is_object($entity)) {
$new_entity = clone $entity;
$this->entityIsFetched = TRUE;
return $new_entity;
}
else {
// drupal_set_message(t("Action: %action fail. It's not possible to fetch entity %entity, bundle %bundle, with id=%id", [
// '%action' => $action->label() . ' [' . $action->id() . ']',
// '%entity' => $entity_type,
// '%bundle' => $bundle,
// '%id' => $id,
// ]), 'error');
return $original_variable_value;
}
}
else {
// drupal_set_message(t("Action: %action fail. Variable: %variable could not be loaded.", [
// '%action' => $action->label() . ' [' . $action->id() . ']',
// '%variable' => $variable->getId(),
// ]), 'error');
return $original_variable_value;
}
} catch (\Exception $e) {
drupal_set_message($e, 'error');
return $original_variable_value;
}
}