function _protected_node_get_paragraph_node_host_entity_id in Protected Node 7
Same name and namespace in other branches
- 1.0.x protected_node.module \_protected_node_get_paragraph_node_host_entity_id()
Helper function to get recursively the host entity nid of the paragraph.
Parameters
\ParagraphsItemEntity $paragraphs_item: A paragraph item.
Return value
int|false Return FALSE if the paragraph or the parent paragraphs are not attached to a node
1 call to _protected_node_get_paragraph_node_host_entity_id()
- protected_node_and_attachment in ./
protected_node.module - Helper function.
File
- ./
protected_node.module, line 1506 - Protected Node module.
Code
function _protected_node_get_paragraph_node_host_entity_id(ParagraphsItemEntity $paragraphs_item) {
// Need to load the host entity otherwise host entity date are null.
paragraphs_item_get_host_entity($paragraphs_item);
$host_entity_type = $paragraphs_item
->hostEntityType();
if ($host_entity_type == 'node') {
return $paragraphs_item
->hostEntity()->nid;
}
elseif ($host_entity_type == 'paragraphs_item') {
$host_id = array(
$paragraphs_item
->hostEntityId(),
);
$host_paragraphs_items = entity_load('paragraphs_item', $host_id);
return _protected_node_get_paragraph_node_host_entity_id(array_shift($host_paragraphs_items));
}
return FALSE;
}