You are here

public function GroupType::postSave in Group 2.0.x

Same name and namespace in other branches
  1. 8 src/Entity/GroupType.php \Drupal\group\Entity\GroupType::postSave()

Acts on a saved entity before the insert or update hook is invoked.

Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.

Overrides ConfigEntityBundleBase::postSave

File

src/Entity/GroupType.php, line 264

Class

GroupType
Defines the Group type configuration entity.

Namespace

Drupal\group\Entity

Code

public function postSave(EntityStorageInterface $storage, $update = TRUE) {
  parent::postSave($storage, $update);
  if (!$update) {

    // Store the id in a short variable for readability.
    $group_type_id = $this
      ->id();

    // @todo Remove this line when https://www.drupal.org/node/2645202 lands.
    $this
      ->setOriginalId($group_type_id);

    // The code below will create the default group roles, synchronized group
    // roles and the group content types for enforced plugins. It is extremely
    // important that we only run this code when we're not dealing with config
    // synchronization.
    //
    // Any of the config entities created here could still be queued up for
    // import in a combined config import. Therefore, we only create them in
    // \Drupal\group\EventSubscriber\ConfigSubscriber after the entire import
    // has finished.
    if (!$this
      ->isSyncing()) {

      /** @var \Drupal\group\Entity\Storage\GroupRoleStorageInterface $group_role_storage */
      $group_role_storage = $this
        ->entityTypeManager()
        ->getStorage('group_role');

      // Enable enforced content plugins for the new group type.
      $this
        ->getContentEnablerManager()
        ->installEnforced($this);

      // Create internal and synchronized group roles for the new group type.
      $group_role_storage
        ->createInternal([
        $group_type_id,
      ]);
      $group_role_storage
        ->createSynchronized([
        $group_type_id,
      ]);
    }
  }
}