public function RequestTree::getDescendant in Subrequests 8
Find a request in a tree based on the request ID.
Parameters
string $request_id: The unique ID of a request in the blueprint to find in this tree.
Return value
\Symfony\Component\HttpFoundation\Request|NULL $request The request if found. NULL if not found.
File
- src/
Blueprint/ RequestTree.php, line 101
Class
- RequestTree
- Contains the hierarchical information of the requests.
Namespace
Drupal\subrequests\BlueprintCode
public function getDescendant($request_id) {
// Search this level's requests.
$found = array_filter($this
->getRequests(), function (Request $request) use ($request_id) {
return $request->attributes
->get(static::SUBREQUEST_ID) == $request_id;
});
if (count($found)) {
return reset($found);
}
// If the request is not in this level, then traverse the children's trees.
$found = array_filter($this
->getRequests(), function (Request $request) use ($request_id) {
/** @var static $sub_tree */
if (!($sub_tree = $request->attributes
->get(static::SUBREQUEST_TREE))) {
return FALSE;
}
return $sub_tree
->getDescendant($request_id);
});
if (count($found)) {
return reset($found);
}
return NULL;
}