-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af48353
commit 249663d
Showing
4 changed files
with
114 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lyrasoft\Luna\Field; | ||
|
||
use Lyrasoft\Luna\Access\AccessService; | ||
use Windwalker\DI\Attributes\Inject; | ||
use Windwalker\Form\Field\ListField; | ||
use Windwalker\Utilities\Enum\EnumTranslatableInterface; | ||
|
||
use function Windwalker\value; | ||
|
||
class UserRoleListField extends ListField | ||
{ | ||
#[Inject] | ||
protected AccessService $accessService; | ||
|
||
protected function prepareOptions(): array | ||
{ | ||
$roles = $this->accessService->getSelectableRoles(); | ||
|
||
$options = []; | ||
|
||
$iAmSuperUser = $this->accessService->isSuperUser(); | ||
|
||
foreach ($roles as $value => $text) { | ||
if ($text instanceof EnumTranslatableInterface || is_numeric($value)) { | ||
$value = value($text); | ||
$text = $this->accessService->wrapUserRole($value)?->getTitle() ?? $value; | ||
} | ||
|
||
if (!$iAmSuperUser && $this->accessService->isSuperUserRole($value)) { | ||
continue; | ||
} | ||
|
||
$options[] = static::createOption($text, (string) $value); | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getAccessors(): array | ||
{ | ||
return array_merge( | ||
parent::getAccessors(), | ||
[] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters