Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to customize the MyProfile page class #312

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ BreezyCore::make()
)
```

#### Custom My Profile page class

You can also use a custom My Profile page class by extending the default one, and registering it with the plugin.

```php
BreezyCore::make()
->myProfile()
->customMyProfilePage(AccountSettingsPage::class),
```

#### Using avatars in your Panel

The instructions for using custom avatars is found in the Filament v3 docs under [Setting up user avatars](https://filamentphp.com/docs/3.x/panels/users#setting-up-user-avatars).
Expand Down
17 changes: 15 additions & 2 deletions src/BreezyCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class BreezyCore implements Plugin
protected bool $passwordUpdateRequireCurrent = true;
protected $sanctumTokens = false;
protected $sanctumPermissions = ["create", "view", "update", "delete"];
protected ?string $customMyProfilePageClass = null;

public function __construct(Google2FA $engine, Repository $cache = null)
{
Expand Down Expand Up @@ -75,7 +76,7 @@ protected function preparePages(): array
{
$collection = collect();
if ($this->myProfile) {
$collection->push(Pages\MyProfilePage::class);
$collection->push($this->getMyProfilePageClass());
}
return $collection->toArray();
}
Expand Down Expand Up @@ -135,6 +136,14 @@ public function myProfile(bool $condition = true, bool $shouldRegisterUserMenu =
return $this;
}

/** @param class-string<Pages\MyProfilePage> $class */
public function customMyProfilePage(string $class)
{
$this->customMyProfilePageClass = $class;

return $this;
}

public function hasAvatars()
{
return $this->myProfile['hasAvatars'];
Expand Down Expand Up @@ -300,5 +309,9 @@ public function getSanctumPermissions(): array
return [$key => $item];
})->toArray();
}


protected function getMyProfilePageClass(): string
{
return $this->customMyProfilePageClass ?? Pages\MyProfilePage::class;
}
}