Как вывести title во вкладке у группы полей

Главные вкладки

Аватар пользователя Sennheiser Sennheiser 14 февраля 2017 в 19:11

Всем привет. Использую модуль field group.
1) Подскажите как вывести Title текущей ноды во вкладке групп полей. Может есть модуль какой который включает поддержку токенов, которые можно прописать в Field group label при создании группы?
2) Вкладки по умолчанию имеют тип заголовка H3. А где можно поменять на H2 ?

ВложениеРазмер
Иконка изображения screenshot_8.jpg44.53 КБ

Комментарии

Аватар пользователя Sennheiser Sennheiser 14 февраля 2017 в 21:24

По второму пункту уточнение:
В файле sites/all/modules/field_group/field_group.module имеется функция:

<?php/**
 * Implements field_group_pre_render_<format-type>.
 * Format type: Accordion item.
 *
 * @param $element The field group form element.
 * @param $group The Field group object prepared for pre_render.
 * @param $form The root element or form.
 */
function field_group_pre_render_accordion_item(&$element, $group, &$form) {

  $element += array(
    '#type' => 'markup',
    '#prefix' => '<h3 class="field-group-format-toggler ' . $group->format_type . ($group->collapsed ? '' : ' field-group-accordion-active') . '"><a href="#">' . check_plain(t($group->label)) . '</a></h3>
    <div class="field-group-format-wrapper ' . $group->classes . '">',
    '#suffix' => '</div>',
    //'#attributes' => array('class' => array($group->format_type)),
  );
  if (!empty($group->description)) {
    $element['#prefix'] .= '<div class="description">' . $group->description . '</div>';
  }

}?>

Мне нужно в ней всего лишь поменять h3 на h2

Как мне переопределить эту функцию??

Аватар пользователя Sennheiser Sennheiser 14 февраля 2017 в 22:34

По идее вот так:

<?php
function mymodule_field_group_pre_render_alter(&$element$group, & $form) {

  if (

$group->format_type == 'accordion_item') {
      
    
$element['#prefix'] = '<h2 class="field-group-format-toggler ' $group->format_type . ($group->collapsed '' ' field-group-accordion-active') . '"><a href="#">' check_plain(t($group->label)) . '</a></h2>
    <div class="field-group-format-wrapper ' 
$group->classes '">';
                           
      
  }

}

?>

А куда этот код сувать? template.php ?

Аватар пользователя Sennheiser Sennheiser 15 февраля 2017 в 1:24

так, вроде получилось: вместо accordion_item надо было писать accordion-item

остался первый пункт - вывести title в названии вкладки (accordion-item).

Аватар пользователя tlito tlito 15 февраля 2017 в 6:45

нужно в этом коде получить id ноды и извлечь из базы данные этой ноды (материала):

http://drupal.stackexchange.com/questions/32309/whats-the-cleanest-way-t...

https://api.drupal.org/api/drupal/modules%21node%21node.module/function/...

в вашем коде на месте t($group->label) написать title

Аватар пользователя Sennheiser Sennheiser 15 февраля 2017 в 14:53

Можете проверить? правильно сделал?

<?php
   
if ($node menu_get_object()) {
    
// Get the nid
     
$nid $node->nid;
    }
       
   
$n node_load($nid);
   
$title $n->title;
  
    
    if (
check_plain(t($group->label)) == 'Новости') {
    
$group->label 'Новости от ' .$title;
  }
?>
Аватар пользователя Sennheiser Sennheiser 15 февраля 2017 в 18:58

Вот так?

<?php

if ($node menu_get_object()) {
    
// Get the nid
     
$nid $node->nid;
    
    
$n node_load($nid);
    
$title $n->title;

    if (

check_plain(t($group->label)) == 'Новости') {
    
$group->label 'Новости от ' .$title;
    }
  }

?>

Итого по всем вопросам в топике вот так получилось, посмотрите пожалуйста косяков нет:

<?php

function mymodule_field_group_pre_render_alter(&$element$group, & $form) {

if (

$node menu_get_object()) {
    
// Get the nid
     
$nid $node->nid;
    
    
$n node_load($nid);
    
$title $n->title;

    if (

check_plain(t($group->label)) == 'Новости') {
    
$group->label 'Новости от ' .$title;
    }
  }

  if (

$group->format_type == 'accordion_item') {       
    
$element['#prefix'] = '<h2 class="field-group-format-toggler ' $group->format_type . ($group->collapsed '' ' field-group-accordion-active') . '"><a href="#">' check_plain(t($group->label)) . '</a></h2>
    <div class="field-group-format-wrapper ' 
$group->classes '">';
                           
  }

}

?>