-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #3207 Improved the IdField used to render primary keys (javie…
…reguiluz) This PR was merged into the 3.0.x-dev branch. Discussion ---------- Improved the IdField used to render primary keys UUIDs and ULIDs are increasingly popular for primary keys ... and they are very long ... so they look ugly in listings. This PR makes primary keys 7-char long max by default ... but you can configure it to use any length. Commits ------- b6e6329 Improved the IdField used to render primary keys
- Loading branch information
Showing
4 changed files
with
58 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Field\Configurator; | ||
|
||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | ||
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; | ||
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface; | ||
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; | ||
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; | ||
use function Symfony\Component\String\u; | ||
|
||
/** | ||
* @author Javier Eguiluz <javier.eguiluz@gmail.com> | ||
*/ | ||
final class IdConfigurator implements FieldConfiguratorInterface | ||
{ | ||
public function supports(FieldDto $field, EntityDto $entityDto): bool | ||
{ | ||
return IdField::class === $field->getFieldFqcn(); | ||
} | ||
|
||
public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $context): void | ||
{ | ||
$maxLength = $field->getCustomOption(IdField::OPTION_MAX_LENGTH); | ||
if (null === $maxLength) { | ||
$maxLength = Crud::PAGE_INDEX === $context->getCrud()->getCurrentPage() ? 7 : -1; | ||
} | ||
|
||
if (-1 !== $maxLength) { | ||
$field->setFormattedValue(u($field->getValue())->truncate($maxLength, '…')); | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #} | ||
{# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #} | ||
{# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #} | ||
{# this template is for entity primary keys (don't format those values as numbers) #} | ||
{{ field.value }} | ||
{# this template is used to display Doctrine entity primary keys #} | ||
{{ field.formattedValue }} |