Skip to content

Instantly share code, notes, and snippets.

@flocondetoile
Created December 12, 2016 14:27
Show Gist options
  • Select an option

  • Save flocondetoile/5cad0906b5db6612ca19fd2dfd499ac8 to your computer and use it in GitHub Desktop.

Select an option

Save flocondetoile/5cad0906b5db6612ca19fd2dfd499ac8 to your computer and use it in GitHub Desktop.
function MYTHEME_preprocess_field__block_content__tabs_block(&$variables){
$variables['entity_reference_target_type'] = $variables['element']['#items']->getItemDefinition()->getSetting('target_type');
$block_uuid = $variables['element']['#object']->toArray()['uuid'][0]['value'];
$blocks = $variables['element']['#items']->referencedEntities();
if (isset($blocks)) {
foreach ($blocks as $key => $block) {
$variables['items'][$key]['block_data']['label'] = $block->label();
if (!empty($block_uuid)) {
$variables['items'][$key]['block_data']['id'] = $block_uuid."-".$key;
} else {
$variables['items'][$key]['block_data']['id'] = $block->id();
}
$variables['items'][$key]['block_data']['active'] = ($key == 0 ? "active" : "");
}
}
}
# File field--block-content--tabs-block.html.twig
{%
set classes = [
'field',
'field--name-' ~ field_name|clean_class,
'field--type-' ~ field_type|clean_class,
'field--label-' ~ label_display,
'field--entity-reference-target-type-' ~ entity_reference_target_type|clean_class,
'clearfix',
]
%}
{%
set title_classes = [
'field__label',
label_display == 'inline' ? 'inline',
]
%}
<div{{ attributes.addClass(classes) }}>
{% if not label_hidden %}
<h3{{ title_attributes.addClass(title_classes) }}>{{ label }}</h3>
{% endif %}
<ul class="nav nav-tabs">
{% for item in items %}
<li class="{{item.block_data.active}}"><a href="#tab-id-{{item.block_data.id}}" data-toggle="tab"><span>{{ item.block_data.label }}</span></a></li>
{% endfor %}
</ul>
<div class="tab-content">
{% for item in items %}
<div class="tab-pane {{item.block_data.active}}" id="tab-id-{{item.block_data.id}}">{{ item.content }}</div>
{% endfor %}
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment