Hi,

I love field_group but I'd like to be able to create my own field group type programatically, or even remove the native ones.

Is there an API for this?

Comments

ericmorand created an issue. See original summary.

eduardo morales alberti’s picture

Hi @ericmorand, yes, it is posible, you must create a new plugin.

If you need an example of it you can download my module https://www.drupal.org/project/field_group_ajaxified_multipage.

We are working on to improve the module, but you can understand how to register a new field_group type.

In addition in a future we will write an article explaining how to do that step by step.

eric morand’s picture

@EduardoMadrid, thanks a lot! I'll give it a try today.

While you're there, can we remove or disable native groups? I'd like to have only custom groups for my client.

Thanks.

eduardo morales alberti’s picture

Hi @ericmorand, Field groups, are custom fields, so if you want new types of fields you need to define it.

Maybe you can use Field group and other contrib fields as example.

Also the module examples https://www.drupal.org/project/examples have some dummy custom fields.

Here you have some tips to create new fields: https://www.drupal.org/docs/8/creating-custom-modules/creating-a-custom-...

eric morand’s picture

@EduardoMadrid, I wanted to disable the default formatters like Accordion, HTMLElement, Details, etc.

I found a way by creating a plugin that use the same id as the official formatters but declare zero supported contexts:

<?php

namespace Drupal\foo\Plugin\field_group\FieldGroupFormatter;

use Drupal\field_group\FieldGroupFormatterBase;

/**
 * Plugin implementation of the 'accordion' formatter.
 *
 * @FieldGroupFormatter(
 *   id = "accordion",
 *   supported_contexts = {
 *   }
 * )
 */
class Accordion extends FieldGroupFormatterBase {

}

Not super clean but I couldn't find another way.

nils.destoop’s picture

Status: Active » Closed (works as designed)

There is a better way. Every plugin type has an alter hook, in the case of fieldgroup it's field_group_formatter_info that can be used as alter hook.
Use that alter hook to remove all default plugins.