protected function AcquiaCohesionDataSuggester::walkRecursiveAndGetSuggestions in TMGMT Translator Smartling 8.4
Only implemented manually because phpunit fails to run tests with closures.
This recursion could be easily rewritten with array_walk_recursive with closure but phpunit serializes data for process isolation purposes which causes exception because closure can not be serialized.
Parameters
mixed $data:
JobItemInterface $jobItem:
Return value
array
1 call to AcquiaCohesionDataSuggester::walkRecursiveAndGetSuggestions()
- AcquiaCohesionDataSuggester::suggestCohesionContentComponents in modules/
tmgmt_smartling_acquia_cohesion/ src/ AcquiaCohesionDataSuggester.php
File
- modules/
tmgmt_smartling_acquia_cohesion/ src/ AcquiaCohesionDataSuggester.php, line 54
Class
Namespace
Drupal\tmgmt_smartling_acquia_cohesionCode
protected function walkRecursiveAndGetSuggestions($data, JobItemInterface $jobItem) {
$suggestions = [];
if (is_string($data) && ($layoutCanvas = $this
->isLayoutCanvas($data))) {
foreach ($layoutCanvas
->iterateCanvas() as $element) {
if ($element
->isComponentContent()) {
// This is the way Acquia Cohesion module uses for fetching number
// from componentId property so used here ias well.
$id = str_replace("cc_", "", $element
->getProperty("componentContentId"));
$componentContent = $this
->loadComponentContent($id);
if (empty($componentContent)) {
$this
->logger("Tried to suggest component content id=@id but failed to load it", [
"@id" => $id,
]);
continue;
}
$suggestions[] = [
'job_item' => tmgmt_job_item_create('content', $componentContent
->getEntityTypeId(), $componentContent
->id()),
'reason' => t('Referenced content component'),
'from_item' => $jobItem
->id(),
];
}
}
}
if (is_array($data)) {
foreach ($data as $key => $value) {
$suggestions += $this
->walkRecursiveAndGetSuggestions($value, $jobItem);
}
}
return $suggestions;
}