public function ProfileType::postSave in Profile 8
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/ ProfileType.php, line 215
Class
- ProfileType
- Defines the profile type entity class.
Namespace
Drupal\profile\EntityCode
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
// Rebuild the user page tab.
\Drupal::service('router.builder')
->setRebuildNeeded();
// Update the "register" form display, if needed.
$original_registration = isset($this->original) ? $this->original
->getRegistration() : FALSE;
$registration = $this
->getRegistration();
if ($original_registration != $registration) {
$register_display = EntityFormDisplay::load('user.user.register');
if (!$register_display) {
// The "register" form mode isn't customized by default.
$default_display = EntityFormDisplay::load('user.user.default');
if (!$default_display) {
// @todo Remove once we require Drupal 8.8. See #2835616.
$default_display = EntityFormDisplay::create([
'targetEntityType' => 'user',
'bundle' => 'user',
'mode' => 'default',
'status' => TRUE,
]);
}
$register_display = $default_display
->createCopy('register');
}
if ($registration) {
$register_display
->setComponent($this
->id() . '_profiles', [
'type' => 'profile_form',
'weight' => 90,
]);
}
else {
$register_display
->removeComponent($this
->id() . '_profiles');
}
$register_display
->setStatus(TRUE);
$register_display
->save();
}
}