You are here

function field_group_group_save in Field Group 8

Same name and namespace in other branches
  1. 8.3 field_group.module \field_group_group_save()
  2. 7.2 field_group.module \field_group_group_save()
  3. 7 field_group.module \field_group_group_save()

Saves a group definition.

This function is called by ctools export when calls are made through ctools_export_crud_save(). It's also used as an api method to add groups to a display.

Parameters

\stdClass $group: A group definition.

\Drupal\Core\Entity\Display\EntityDisplayInterface $display: The display to update if known.

Return value

\Drupal\Core\Entity\Display\EntityDisplayInterface|NULL The updated entity display.

6 calls to field_group_group_save()
EntityDisplayTest::testHtmlElement in tests/src/Functional/EntityDisplayTest.php
Test the html element formatter.
EntityDisplayTest::testTabs in tests/src/Functional/EntityDisplayTest.php
Test the tabs formatter.
FieldGroupAddForm::submitForm in src/Form/FieldGroupAddForm.php
Form submission handler.
FieldGroupTestTrait::createGroup in tests/src/Functional/FieldGroupTestTrait.php
Create a new group.
field_group_field_overview_submit in includes/field_ui.inc
Submit handler for the overview screens.

... See full list

File

./field_group.module, line 590
Allows administrators to attach custom fields to fieldable types.

Code

function field_group_group_save($group, $display = NULL) {
  if ($display === NULL) {
    if ($group->context == 'form') {
      $display = EntityFormDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode);
    }
    elseif ($group->context == 'view') {
      $display = EntityViewDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode);
    }
  }

  // If no display was found. It doesn't exist yet, create it.
  if (!isset($display)) {
    if ($group->context == 'form') {
      $display = EntityFormDisplay::create(array(
        'targetEntityType' => $group->entity_type,
        'bundle' => $group->bundle,
        'mode' => $group->mode,
      ))
        ->setStatus(TRUE);
    }
    elseif ($group->context == 'view') {
      $display = EntityViewDisplay::create(array(
        'targetEntityType' => $group->entity_type,
        'bundle' => $group->bundle,
        'mode' => $group->mode,
      ))
        ->setStatus(TRUE);
    }
  }
  if (isset($display)) {
    $data = (array) $group;
    unset($data['group_name'], $data['entity_type'], $data['bundle'], $data['mode'], $data['form'], $data['context']);
    $display
      ->setThirdPartySetting('field_group', $group->group_name, $data);
    $display
      ->save();
  }
  return $display;
}