FormatterHelper.php in Field Group 8.3
File
src/FormatterHelper.php
View source
<?php
namespace Drupal\field_group;
use Drupal;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Security\TrustedCallbackInterface;
class FormatterHelper implements TrustedCallbackInterface {
public static function formatterOptions($type) {
$options =& drupal_static(__FUNCTION__);
if (!isset($options)) {
$options = [];
$manager = \Drupal::service('plugin.manager.field_group.formatters');
$formatters = $manager
->getDefinitions();
foreach ($formatters as $formatter) {
if (in_array($type, $formatter['supported_contexts'])) {
$options[$formatter['id']] = $formatter['label'];
}
}
}
return $options;
}
public static function entityViewPrender(array $element) {
field_group_build_entity_groups($element, 'view');
return $element;
}
public static function formProcess(array &$element, FormStateInterface $form_state = NULL, array &$form = []) {
if (empty($element['#field_group_form_process'])) {
$element['#field_group_form_process'] = TRUE;
if (empty($element['#fieldgroups'])) {
return $element;
}
$group_references = [];
foreach ($element['#fieldgroups'] as $group_name => $group) {
if (!isset($element[$group_name])) {
$element[$group_name] = [];
}
$group_parents = $element['#array_parents'];
$group_parents[] = empty($group->parent_name) ? $group->region : $group->parent_name;
$group_references[$group_name] =& $element[$group_name];
$element[$group_name]['#group'] = implode('][', $group_parents);
$parents = $element['#array_parents'];
$parents[] = $group_name;
$element[$group_name]['#parents'] = $parents;
$group_children_parent_group = implode('][', $parents);
foreach ($group->children as $child) {
if (!empty($element[$child]['#field_group_ignore'])) {
continue;
}
$element[$child]['#group'] = $group_children_parent_group;
}
}
foreach ($element['#fieldgroups'] as $group_name => $group) {
$field_group_element =& $element[$group_name];
foreach (Drupal::moduleHandler()
->getImplementations('field_group_form_process') as $module) {
$function = $module . '_field_group_form_process';
$function($field_group_element, $group, $element);
}
Drupal::moduleHandler()
->alter('field_group_form_process', $field_group_element, $group, $element);
}
Drupal::moduleHandler()
->alter('field_group_form_process_build', $element, $form_state, $form);
}
return $element;
}
public static function trustedCallbacks() {
return [
'entityViewPrender',
'formProcess',
];
}
}