You are here

public function UserProfile::getEntity in Flexiform 8

Get the Entity.

Overrides FlexiformFormEntityBase::getEntity

File

src/Plugin/FlexiformFormEntity/UserProfile.php, line 76

Class

UserProfile
Form Entity for getting profiles from a user object.

Namespace

Drupal\flexiform\Plugin\FlexiformFormEntity

Code

public function getEntity() {
  $user = $this
    ->getContextValue('user');
  if (!$user) {
    return NULL;
  }
  $profile_storage = $this->entityTypeManager
    ->getStorage('profile');
  try {
    if ($user
      ->id() && ($entity = $profile_storage
      ->loadDefaultByUser($user, $this
      ->getBundle()))) {
      return $entity;
    }
    elseif (!empty($this->configuration['create'])) {
      $entity = $this
        ->createEntity();
      return $entity;
    }
  } catch (\Exception $e) {
    return NULL;
  }
}