getRequest()->getAttribute('identity'); $identity = $identity ?? []; $loggedUserId = $identity['id'] ?? null; $isCurrentUser = false; if (!Configure::read('Users.Profile.viewOthers') || empty($id)) { $id = $loggedUserId; } try { $appContain = (array)Configure::read('Auth.Profile.contain'); $socialContain = Configure::read('Users.Social.login') ? ['SocialAccounts'] : []; $user = $this->getUsersTable()->get($id, contain: array_merge($appContain, $socialContain)); $this->set('avatarPlaceholder', Configure::read('Users.Avatar.placeholder')); if ($user->id === $loggedUserId) { $isCurrentUser = true; } } catch (RecordNotFoundException $ex) { $this->Flash->error(__d('cake_d_c/users', 'User was not found')); return $this->redirect($this->getRequest()->referer() ?? '/'); } catch (InvalidPrimaryKeyException $ex) { $this->Flash->error(__d('cake_d_c/users', 'Not authorized, please login first')); return $this->redirect($this->getRequest()->referer() ?? '/'); } $this->set(['user' => $user, 'isCurrentUser' => $isCurrentUser]); $this->viewBuilder()->setOption('serialize', ['user', 'isCurrentUser']); } }