function lingotek_get_paragraph_parent_info in Lingotek Translation 7.7
Get a paragraph's parent entity info
5 calls to lingotek_get_paragraph_parent_info()
- LingotekEntity::getTitle in lib/
Drupal/ lingotek/ LingotekEntity.php - lingotek_bulk_grid_filter_search_box in ./
lingotek.bulk_grid.inc - lingotek_bulk_grid_parse_table_data in ./
lingotek.bulk_grid.inc - lingotek_get_entity_edit_link in ./
lingotek.bulk_grid.inc - lingotek_render_title in ./
lingotek.bulk_grid.inc
File
- ./
lingotek.util.inc, line 3266 - Utility functions.
Code
function lingotek_get_paragraph_parent_info($entity_type, $entity_id) {
$paragraph = lingotek_entity_load_single($entity_type, $entity_id);
$host_entity = $paragraph
->hostEntity();
$max_depth = 10;
$level = 0;
// Find the top-level parent entity
while (get_class($host_entity) === 'ParagraphsItemEntity') {
$level++;
$host_entity = $paragraph
->hostEntity();
$paragraph = $host_entity;
if ($level == $max_depth) {
break;
}
}
$parent_id = isset($host_entity->nid) ? $host_entity->nid : -1;
$parent_title = isset($host_entity->title) ? $host_entity->title : 'N/A';
return array(
$parent_id,
$parent_title,
);
}