You are here

function social_profile_profile_presave in Open Social 10.3.x

Same name and namespace in other branches
  1. 10.2.x modules/social_features/social_profile/social_profile.module \social_profile_profile_presave()

Implements hook_ENTITY_TYPE_presave().

Set the correct profile name.

File

modules/social_features/social_profile/social_profile.module, line 963
The Social profile module.

Code

function social_profile_profile_presave(EntityInterface $profile) {
  if ($profile instanceof ProfileInterface) {

    /** @var \Drupal\social_profile\SocialProfileNameService $profile_name_service */
    $profile_name_service = \Drupal::service('social_profile.name_service');

    // Check if we need update Profile name.
    if (!$profile_name_service
      ->needToUpdateProfileName($profile)) {
      return;
    }

    // Get generated profile name.
    $profile_name = $profile_name_service
      ->getProfileName($profile);

    // Update profile name.
    $profile
      ->set('profile_name', $profile_name);
  }
}