Skip to content

Commit

Permalink
"Credentialed" user attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Dec 14, 2024
1 parent 7b5fd77 commit 7112349
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Improved the styling of inline code fragments. ([#16141](https://github.com/craftcms/cms/pull/16141))
- Improved the styling of attribute previews in card view. ([#16324](https://github.com/craftcms/cms/pull/16324))
- Added the “Affiliated Site” user condition rule. ([#16174](https://github.com/craftcms/cms/pull/16174))
- Added the “Credentialed” user card/table attribute.
- The global sidebar no longer shows “Failed” for queue jobs, for users that don’t have access to the Queue Manager. ([#16184](https://github.com/craftcms/cms/issues/16184))
- Addresses and Matrix fields now show provisional drafts when previewing an owner element. ([#16295](https://github.com/craftcms/cms/issues/16295))
- Color fields with a predefined color palette now primarily show a color select dropdown, rather than a manual color input. ([#16249](https://github.com/craftcms/cms/pull/16249))
Expand Down
21 changes: 21 additions & 0 deletions src/elements/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
use craft\fieldlayoutelements\users\FullNameField;
use craft\helpers\App;
use craft\helpers\ArrayHelper;
use craft\helpers\Cp;
use craft\helpers\DateTimeHelper;
use craft\helpers\Db;
use craft\helpers\Html;
use craft\helpers\Json;
use craft\helpers\Session;
use craft\helpers\StringHelper;
use craft\helpers\Template;
use craft\helpers\UrlHelper;
use craft\helpers\User as UserHelper;
use craft\i18n\Formatter;
Expand Down Expand Up @@ -468,6 +470,7 @@ protected static function defineTableAttributes(): array
'preferredLanguage' => ['label' => Craft::t('app', 'Preferred Language')],
'preferredLocale' => ['label' => Craft::t('app', 'Preferred Locale')],
'lastLoginDate' => ['label' => Craft::t('app', 'Last Login')],
'isCredentialed' => ['label' => Craft::t('app', 'Credentialed')],
]));
}

Expand Down Expand Up @@ -538,6 +541,14 @@ protected static function defineCardAttributes(): array
'label' => Craft::t('app', 'Preferred Locale'),
'placeholder' => $i18n->getLocaleById('en-US')->getDisplayName(Craft::$app->language),
],
'isCredentialed' => [
'label' => Craft::t('app', 'Credentialed'),
'placeholder' => Template::raw(Cp::statusLabelHtml([
'color' => Color::Teal,
'label' => Craft::t('app', 'Credentialed'),
'icon' => 'check',
])),
],
'lastLoginDate' => [
'label' => Craft::t('app', 'Last Login'),
'placeholder' => (new \DateTime())->sub(new \DateInterval('P14D')),
Expand Down Expand Up @@ -2308,6 +2319,16 @@ protected function attributeHtml(string $attribute): string
case 'preferredLocale':
$locale = $this->getPreferredLocale();
return $locale ? Craft::$app->getI18n()->getLocaleById($locale)->getDisplayName(Craft::$app->language) : '';

case 'isCredentialed':
$value = $this->getIsCredentialed();
if ($this->viewMode === 'cards') {
return Cp::statusLabelHtml([
'color' => $value ? Color::Teal : Color::Gray,
'label' => Craft::t('app', 'Credentialed'),
'icon' => $value ? 'check' : 'xmark',
]);
}
}

return parent::attributeHtml($attribute);
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/ElementHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,10 @@ public static function attributeHtml(mixed $value): string
]);
}

if ($value instanceof Markup) {
return (string)$value;
}

try {
$value = (string)$value;
} catch (Throwable) {
Expand Down

0 comments on commit 7112349

Please sign in to comment.