Skip to content

Instantly share code, notes, and snippets.

@emerham
Created January 11, 2020 00:56
Show Gist options
  • Save emerham/9b359046dfca5ced887549694c442af0 to your computer and use it in GitHub Desktop.
Save emerham/9b359046dfca5ced887549694c442af0 to your computer and use it in GitHub Desktop.
<?php
// Rendering Paragraphs Menu Items
$paragraph_items = field_get_items('paragraphs_item', $variables['paragraphs_item'], 'field_p_menu');
$field_collection = field_collection_field_get_entity($paragraph_items[0], 'field_p_menu');
print render(field_view_field('field_collection_item', $field_collection, 'field_p_menu_link', [
'type' => 'link_title_plain',
'label' => 'hidden'
]));
print render(field_view_field('field_collection_item', $field_collection, 'field_p_menu_link', [
'type' => 'link_plain',
'label' => 'hidden'
]));
$html = '<div class="' . $classes . '"><ul>';
for ($i = 0; $i < $items; $i++) {
$id = $content['field_p_menu']['#items'][$i]['value'];
$loc = $content['field_p_menu'][$i]['entity']['field_collection_item'][$id]['field_p_menu_link']['#items'][0];
$icon = $content['field_p_menu'][$i]['entity']['field_collection_item'][$id]['field_p_menu_icon']['#items'][0]['value'];
if (!empty($loc['url'])) {
if (isset($loc['fragment'])) {
$html .= '<li><a href="' . $loc['url'] . '#' . $loc['fragment'] . '">';
}
else {
$html .= '<li><a href="' . $loc['url'] . '">';
}
if (!empty($icon)) {
$html .= '<i class="' . $icon . '"></i>';
}
$html .= $loc['title'] . '</a></li>';
}
else {
if (!empty($loc['title']) | !empty($icon)) {
$html .= '<li><span class="noLink">';
if (!empty($icon)) {
$html .= '<i class="' . $icon . '"></i>';
}
if (!empty($loc['title'])) {
$html .= $loc['title'];
}
$html .= '</span></li>';
}
}
}
$html .= '</ul></div>';
echo $html;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment