Add hook_farm_ui_theme_field_group_items to collect field group mappings
This commit is contained in:
parent
69d9ef713b
commit
abd6ee9646
|
@ -14,6 +14,27 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Specify the field groups to place entity fields in.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
* @param string $bundle
|
||||
* The bundle.
|
||||
*
|
||||
* @return string[]
|
||||
* An array keyed by field ID mapping to field group.
|
||||
*/
|
||||
function hook_farm_ui_theme_field_group_items(string $entity_type, string $bundle) {
|
||||
if ($entity_type == 'asset' && $bundle == 'animal') {
|
||||
return [
|
||||
'nickname' => 'bundle',
|
||||
'sex' => 'bundle',
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the regions that asset, log, and plan content items should be in.
|
||||
*
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\Core\Block\BlockPluginInterface;
|
||||
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
|
@ -52,6 +53,31 @@ function farm_ui_theme_theme_suggestions_menu_local_tasks(array $variables) {
|
|||
return ['menu_local_tasks__farm'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_form_display_alter().
|
||||
*/
|
||||
function farm_ui_theme_entity_form_display_alter(EntityFormDisplayInterface $form_display, array $context) {
|
||||
|
||||
// Only alter farm entity types.
|
||||
$entity_types = ['asset', 'log', 'plan'];
|
||||
if (!in_array($context['entity_type'], $entity_types)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ask modules for a list of field group items.
|
||||
$field_map = \Drupal::moduleHandler()->invokeAll(
|
||||
'farm_ui_theme_field_group_items',
|
||||
[$context['entity_type'], $context['bundle']],
|
||||
);
|
||||
|
||||
// Apply the field group mapping if not already specified on the form display.
|
||||
foreach ($field_map as $field_id => $field_group) {
|
||||
if (($renderer = $form_display->getRenderer($field_id)) && !$renderer->getThirdPartySetting('farm_ui_theme', 'field_group', FALSE)) {
|
||||
$renderer->setThirdPartySetting('farm_ui_theme', 'field_group', $field_group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_gin_content_form_routes().
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue