For anyone else trying to get field groups to show up on a custom entity display, I found the following. Working within field_layout regions too.
1. Add to theme registry.
```
/**
* Implements hook_theme().
*/
function MY_MODULE_theme($existing, $type, $theme, $path) {
return [
'MY_ENTITY' => [
'render element' => 'elements',
],
];
}
```
2. Prepare the entity template variables beneath the 'content' key.
```
function template_preprocess_MY_ENTITY(&$variables) {
$variables['view_mode'] = $variables['elements']['#view_mode'];
// Helpful $content variable for templates.
$variables += ['content' => []];
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
```
3. Add MY-ENTITY.html.twig file to templates
With at least:
```
{{ content }}
```
Oops. Better patch attached.
A drawback of the above seems to be that a hyperlinked image continues to be hyperlinked even when rendered inside the wysiwyg editor. A user wouldn't expect that clicking on an element inside the editor would result in linking away from the page.
The new logic within template_preprocess_entity_embed_container perhaps shouldn't fire when embedding inside the wysiwyg.
Patched attached, but possibly there is a better way rather than checking the route.
I think this is a core issue. See https://www.drupal.org/project/drupal/issues/3300404 📌 Unserialize(): Passing null to parameter #1 ($data) of type string is deprecated in Drupal\Core\Entity\Sql\SqlContentEntityStorage Needs work
Sorry, jumped the gun a bit on that one. This patch should be better
Re-rolled the patch so other attributes can also have multiple values.
Why was this marked as fixed without being merged?