Is it possible / how to generate the "Field group label" dynamically?
e.g. setup a field group with "accordion item" format where the node title used as the field group label
or setup a field group with "horizontal tab item" format where the current username used as the field group label.

I think what i need is token integration, does this module already support it? is it easy to add this functionality?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Stalski’s picture

Status: Active » Closed (won't fix)

This is not supported within fieldgroup. Fieldgroup has no notion of "node title" and I don't think it should.

You could do it custom, but it won't be incorporated into this module.

Ontwerpt’s picture

I have added the following code to field_group/horizontal-tabs.js #180
I am using the Pathauto-module and wanted to take the Page title for the first tab, but strip everything after |

jQuery(document).ready(function () {
	var url = jQuery(this).attr('title');
	var n = url.indexOf('|');
 	url = url.substring(0, n != -1 ? n : url.length);
	jQuery('#this_url').html('<strong>' + url + '</strong>');
});
/**
 * Theme function for a horizontal tab.
 *
 * @param settings
 *   An object with the following keys:
 *   - title: The name of the tab.
 * @return
 *   This function has to return an object with at least these keys:
 *   - item: The root tab jQuery element
 *   - link: The anchor tag that acts as the clickable area of the tab
 *       (jQuery version)
 *   - summary: The jQuery element that contains the tab summary
 */
Drupal.theme.prototype.horizontalTab = function (settings) {
  var tab = {};
  tab.item = $('<li class="horizontal-tab-button" tabindex="-1"></li>')
    .append(tab.link = $('<a href="#"><span id="this_url"></span></a>')
      .append(tab.title = $('<span class="label"></label>').text(settings.title))
      .append(tab.summary = $('<span class="summary"></span>')
    )
  );
  return tab;
};

})(jQuery);

I still needed the default tab title on my second tab, so I only hid the first label through CSS.

Dubs’s picture

Status: Closed (won't fix) » Active
FileSize
529 bytes
5.33 KB

I've added some code to the module to handle this.

"Field Group" does have an idea what the node is (but perhaps not in all circumstances?). Tokens can be used and the node object seems to be available on the $form object passed to all the pre-render functions, so we can pass this along to the token module. I've added a check to make sure the node is supplied first just in case it's missing for some reason (I don't fully know the scope of this module).

It works for me and I'm using horizontal tabs with [node:title] as the token.

I've made a patch to handle the tokens. I realise this would make Token a dependency but I think it's worth it. Please can this be tested and added as it would be really useful. I'm not using GIT but DIFF on a local file system so apologies if the patch looks weird.

Thanks,

David

Dubs’s picture

Category: support » feature
Status: Active » Needs review
nils.destoop’s picture

Status: Needs review » Closed (works as designed)

I reviewed your code, but it's not really something to go into fieldgroup. The patch only works for node forms. Fieldgroup works on more the only the node forms. It works on both forms and display for every entity. If you find a better solution that works for all entities, you can re-open this. Also make sure, that there is no dependency on token module. (fallback to normal title, when no token available)

Stalski’s picture

If field_group would depend on entity (which does not make much sense in D7, it will in D8), then the token integration would be more valid.

Stalski’s picture

If field_group would depend on entity (which does not make much sense in D7, it will in D8), then the token integration would be more valid.

jade.mese’s picture

Status: Closed (works as designed) » Active

Hello!

I try to explain my problem.
I have a dance style and I have more courses for each dance styles (beginner, intermediate, advanced, etc.)
Dance style is a content type. Courses are field collections.
I would like to display the course information in a fieldset (field group), and the title of the course should be the legend.
http://parkettklub.sch.bme.hu/tanfolyam/salsa/kezdo
I tried to add the [node:field-course:#:field_course_title] token to the field group title, but it does not work. :(
Do you know any solution for my problem?

Thanks!

tchopshop’s picture

Issue summary: View changes

I'd like to dynamically add a class on a wrapper for a file field with a token from another field. I'm using field group to add static classes around the file field, but I'd like to add a class based on user interaction (selecting from a list).

I can't figure out how this can be done, apart from custom programming. Field group seemed like it would do it, but I didn't realize until just now that tokens don't work in the "Extra Classes" field.

I hope you might think about adding this type of functionality.

petednz’s picture

I think I am after the same solution. Scenario is each Field Set has a field called "Topic" and I would love to be able to show that topic as part of the label of the field group, so it is visible when collapsed.
But then this seems like a common request so I suspect I may be going about this the wrong way.
(r6785)

akz’s picture

Status: Active » Closed (won't fix)

Comments https://www.drupal.org/node/1306034#comment-6396562 and https://www.drupal.org/node/1306034#comment-6396750 perfectly explain why this feature request is not valid and why this issue is marked as Closed.

geek-merlin’s picture

Yes this can be a custom module. Maybe i'll implement this later.
Note to myself: Use hook_field_group_pre_render()