mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-13 11:54:32 +02:00
Applied rector with PHP8.1 migration rules
This commit is contained in:
parent
dc6a67c2f0
commit
7ee01d9a05
303 changed files with 1228 additions and 3465 deletions
|
@ -32,11 +32,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class AttachmentTypeAdminForm extends BaseEntityAdminForm
|
||||
{
|
||||
protected FileTypeFilterTools $filterTools;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security, FileTypeFilterTools $filterTools, EventCommentNeededHelper $eventCommentNeededHelper)
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security, protected FileTypeFilterTools $filterTools, EventCommentNeededHelper $eventCommentNeededHelper)
|
||||
{
|
||||
$this->filterTools = $filterTools;
|
||||
parent::__construct($security, $eventCommentNeededHelper);
|
||||
}
|
||||
|
||||
|
@ -58,12 +55,8 @@ class AttachmentTypeAdminForm extends BaseEntityAdminForm
|
|||
|
||||
//Normalize data before writing it to database
|
||||
$builder->get('filetype_filter')->addViewTransformer(new CallbackTransformer(
|
||||
static function ($value) {
|
||||
return $value;
|
||||
},
|
||||
function ($value) {
|
||||
return $this->filterTools->normalizeFilterString($value);
|
||||
}
|
||||
static fn($value) => $value,
|
||||
fn($value) => $this->filterTools->normalizeFilterString($value)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,13 +44,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class BaseEntityAdminForm extends AbstractType
|
||||
{
|
||||
protected \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
protected EventCommentNeededHelper $eventCommentNeededHelper;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security, EventCommentNeededHelper $eventCommentNeededHelper)
|
||||
public function __construct(protected \Symfony\Bundle\SecurityBundle\Security $security, protected EventCommentNeededHelper $eventCommentNeededHelper)
|
||||
{
|
||||
$this->security = $security;
|
||||
$this->eventCommentNeededHelper = $eventCommentNeededHelper;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
@ -82,7 +77,7 @@ class BaseEntityAdminForm extends AbstractType
|
|||
'parent',
|
||||
StructuralEntityType::class,
|
||||
[
|
||||
'class' => get_class($entity),
|
||||
'class' => $entity::class,
|
||||
'required' => false,
|
||||
'label' => 'parent.label',
|
||||
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity),
|
||||
|
|
|
@ -32,12 +32,9 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class CurrencyAdminForm extends BaseEntityAdminForm
|
||||
{
|
||||
private string $default_currency;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security, EventCommentNeededHelper $eventCommentNeededHelper, string $default_currency)
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security, EventCommentNeededHelper $eventCommentNeededHelper, private readonly string $default_currency)
|
||||
{
|
||||
parent::__construct($security, $eventCommentNeededHelper);
|
||||
$this->default_currency = $default_currency;
|
||||
}
|
||||
|
||||
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void
|
||||
|
|
|
@ -37,11 +37,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class ImportType extends AbstractType
|
||||
{
|
||||
protected \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security)
|
||||
public function __construct(protected \Symfony\Bundle\SecurityBundle\Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
|
|
@ -32,11 +32,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class MassCreationForm extends AbstractType
|
||||
{
|
||||
protected \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security)
|
||||
public function __construct(protected \Symfony\Bundle\SecurityBundle\Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
|
|
@ -32,12 +32,9 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class SupplierForm extends CompanyForm
|
||||
{
|
||||
protected string $default_currency;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security, EventCommentNeededHelper $eventCommentNeededHelper, string $default_currency)
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security, EventCommentNeededHelper $eventCommentNeededHelper, protected string $default_currency)
|
||||
{
|
||||
parent::__construct($security, $eventCommentNeededHelper);
|
||||
$this->default_currency = $default_currency;
|
||||
}
|
||||
|
||||
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void
|
||||
|
|
|
@ -48,25 +48,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
|
||||
class AttachmentFormType extends AbstractType
|
||||
{
|
||||
protected AttachmentManager $attachment_helper;
|
||||
protected UrlGeneratorInterface $urlGenerator;
|
||||
protected bool $allow_attachments_download;
|
||||
protected string $max_file_size;
|
||||
protected \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
protected AttachmentSubmitHandler $submitHandler;
|
||||
protected TranslatorInterface $translator;
|
||||
|
||||
public function __construct(AttachmentManager $attachmentHelper, UrlGeneratorInterface $urlGenerator,
|
||||
\Symfony\Bundle\SecurityBundle\Security $security, AttachmentSubmitHandler $submitHandler, TranslatorInterface $translator,
|
||||
bool $allow_attachments_downloads, string $max_file_size)
|
||||
public function __construct(protected AttachmentManager $attachment_helper, protected UrlGeneratorInterface $urlGenerator, protected \Symfony\Bundle\SecurityBundle\Security $security, protected AttachmentSubmitHandler $submitHandler, protected TranslatorInterface $translator, protected bool $allow_attachments_download, protected string $max_file_size)
|
||||
{
|
||||
$this->attachment_helper = $attachmentHelper;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->allow_attachments_download = $allow_attachments_downloads;
|
||||
$this->security = $security;
|
||||
$this->submitHandler = $submitHandler;
|
||||
$this->translator = $translator;
|
||||
$this->max_file_size = $max_file_size;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
|
|
@ -67,11 +67,8 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
|||
*/
|
||||
class CollectionTypeExtension extends AbstractTypeExtension
|
||||
{
|
||||
protected PropertyAccessorInterface $propertyAccess;
|
||||
|
||||
public function __construct(PropertyAccessorInterface $propertyAccess)
|
||||
public function __construct(protected PropertyAccessorInterface $propertyAccess)
|
||||
{
|
||||
$this->propertyAccess = $propertyAccess;
|
||||
}
|
||||
|
||||
public static function getExtendedTypes(): iterable
|
||||
|
@ -93,9 +90,7 @@ class CollectionTypeExtension extends AbstractTypeExtension
|
|||
|
||||
//Set a unique prototype name, so that we can use nested collections
|
||||
$resolver->setDefaults([
|
||||
'prototype_name' => function (Options $options) {
|
||||
return '__name_'.uniqid("", false) . '__';
|
||||
},
|
||||
'prototype_name' => fn(Options $options): string => '__name_'.uniqid("", false) . '__',
|
||||
]);
|
||||
|
||||
$resolver->setAllowedTypes('reindex_enable', 'bool');
|
||||
|
@ -156,7 +151,7 @@ class CollectionTypeExtension extends AbstractTypeExtension
|
|||
//The validator uses the number of the element as index, so we have to map the errors to the correct index
|
||||
$error_mapping = [];
|
||||
$n = 0;
|
||||
foreach ($data as $key => $item) {
|
||||
foreach (array_keys($data) as $key) {
|
||||
$error_mapping['['.$n.']'] = $key;
|
||||
$n++;
|
||||
}
|
||||
|
|
|
@ -27,11 +27,8 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
|
||||
class InstanceOfConstraintType extends AbstractType
|
||||
{
|
||||
protected EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
public function __construct(protected EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $entityManager;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
|
|
|
@ -30,11 +30,8 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|||
|
||||
class TagsConstraintType extends AbstractType
|
||||
{
|
||||
protected UrlGeneratorInterface $urlGenerator;
|
||||
|
||||
public function __construct(UrlGeneratorInterface $urlGenerator)
|
||||
public function __construct(protected UrlGeneratorInterface $urlGenerator)
|
||||
{
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
|
|
@ -53,11 +53,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class LabelOptionsType extends AbstractType
|
||||
{
|
||||
private \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security)
|
||||
public function __construct(private readonly \Symfony\Bundle\SecurityBundle\Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
@ -101,7 +98,7 @@ class LabelOptionsType extends AbstractType
|
|||
'label_options.barcode_type.code93' => 'code93',
|
||||
'label_options.barcode_type.datamatrix' => 'datamatrix',
|
||||
],
|
||||
'group_by' => static function ($choice, $key, $value) {
|
||||
'group_by' => static function ($choice, $key, $value): ?string {
|
||||
if (in_array($choice, ['qr', 'datamatrix'], true)) {
|
||||
return 'label_options.barcode_type.2D';
|
||||
}
|
||||
|
|
|
@ -52,11 +52,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class LabelDialogType extends AbstractType
|
||||
{
|
||||
protected \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security)
|
||||
public function __construct(protected \Symfony\Bundle\SecurityBundle\Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
|
|
@ -40,11 +40,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class OrderdetailType extends AbstractType
|
||||
{
|
||||
protected \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security)
|
||||
public function __construct(protected \Symfony\Bundle\SecurityBundle\Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
@ -82,7 +79,7 @@ class OrderdetailType extends AbstractType
|
|||
$orderdetail = $event->getData();
|
||||
|
||||
$dummy_pricedetail = new Pricedetail();
|
||||
if (null !== $orderdetail && null !== $orderdetail->getSupplier()) {
|
||||
if ($orderdetail instanceof \App\Entity\PriceInformations\Orderdetail && $orderdetail->getSupplier() instanceof \App\Entity\Parts\Supplier) {
|
||||
$dummy_pricedetail->setCurrency($orderdetail->getSupplier()->getDefaultCurrency());
|
||||
}
|
||||
|
||||
|
|
|
@ -52,15 +52,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class PartBaseType extends AbstractType
|
||||
{
|
||||
protected \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
protected UrlGeneratorInterface $urlGenerator;
|
||||
protected EventCommentNeededHelper $event_comment_needed_helper;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security, UrlGeneratorInterface $urlGenerator, EventCommentNeededHelper $event_comment_needed_helper)
|
||||
public function __construct(protected \Symfony\Bundle\SecurityBundle\Security $security, protected UrlGeneratorInterface $urlGenerator, protected EventCommentNeededHelper $event_comment_needed_helper)
|
||||
{
|
||||
$this->security = $security;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->event_comment_needed_helper = $event_comment_needed_helper;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
|
|
@ -38,11 +38,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class PartLotType extends AbstractType
|
||||
{
|
||||
protected \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security)
|
||||
public function __construct(protected \Symfony\Bundle\SecurityBundle\Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
|
|
@ -30,12 +30,10 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
|
||||
class PermissionGroupType extends AbstractType
|
||||
{
|
||||
protected PermissionManager $resolver;
|
||||
protected array $perm_structure;
|
||||
|
||||
public function __construct(PermissionManager $resolver)
|
||||
public function __construct(protected PermissionManager $resolver)
|
||||
{
|
||||
$this->resolver = $resolver;
|
||||
$this->perm_structure = $resolver->getPermissionStructure();
|
||||
}
|
||||
|
||||
|
@ -68,9 +66,7 @@ class PermissionGroupType extends AbstractType
|
|||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefault('group_name', static function (Options $options) {
|
||||
return trim($options['name']);
|
||||
});
|
||||
$resolver->setDefault('group_name', static fn(Options $options): string => trim((string) $options['name']));
|
||||
|
||||
$resolver->setDefault('inherit', false);
|
||||
|
||||
|
|
|
@ -33,12 +33,10 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
|
||||
class PermissionType extends AbstractType
|
||||
{
|
||||
protected PermissionManager $resolver;
|
||||
protected array $perm_structure;
|
||||
|
||||
public function __construct(PermissionManager $resolver)
|
||||
public function __construct(protected PermissionManager $resolver)
|
||||
{
|
||||
$this->resolver = $resolver;
|
||||
$this->perm_structure = $resolver->getPermissionStructure();
|
||||
}
|
||||
|
||||
|
@ -46,9 +44,7 @@ class PermissionType extends AbstractType
|
|||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefault('perm_name', static function (Options $options) {
|
||||
return $options['name'];
|
||||
});
|
||||
$resolver->setDefault('perm_name', static fn(Options $options) => $options['name']);
|
||||
|
||||
$resolver->setDefault('label', function (Options $options) {
|
||||
if (!empty($this->perm_structure['perms'][$options['perm_name']]['label'])) {
|
||||
|
@ -58,9 +54,7 @@ class PermissionType extends AbstractType
|
|||
return $options['name'];
|
||||
});
|
||||
|
||||
$resolver->setDefault('multi_checkbox', static function (Options $options) {
|
||||
return !$options['disabled'];
|
||||
});
|
||||
$resolver->setDefault('multi_checkbox', static fn(Options $options) => !$options['disabled']);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'inherit' => false,
|
||||
|
|
|
@ -34,13 +34,8 @@ use Traversable;
|
|||
*/
|
||||
final class PermissionsMapper implements DataMapperInterface
|
||||
{
|
||||
private PermissionManager $resolver;
|
||||
private bool $inherit;
|
||||
|
||||
public function __construct(PermissionManager $resolver, bool $inherit = false)
|
||||
public function __construct(private readonly PermissionManager $resolver, private readonly bool $inherit = false)
|
||||
{
|
||||
$this->inherit = $inherit;
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,12 +33,10 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
|
||||
class PermissionsType extends AbstractType
|
||||
{
|
||||
protected PermissionManager $resolver;
|
||||
protected array $perm_structure;
|
||||
|
||||
public function __construct(PermissionManager $resolver)
|
||||
public function __construct(protected PermissionManager $resolver)
|
||||
{
|
||||
$this->resolver = $resolver;
|
||||
$this->perm_structure = $resolver->getPermissionStructure();
|
||||
}
|
||||
|
||||
|
|
|
@ -38,11 +38,8 @@ use Symfony\Component\Security\Core\Security;
|
|||
|
||||
class ProjectBuildType extends AbstractType implements DataMapperInterface
|
||||
{
|
||||
private \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security)
|
||||
public function __construct(private readonly \Symfony\Bundle\SecurityBundle\Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
|
@ -79,10 +76,10 @@ class ProjectBuildType extends AbstractType implements DataMapperInterface
|
|||
$form->add('addBuildsToBuildsPart', CheckboxType::class, [
|
||||
'label' => 'project.build.add_builds_to_builds_part',
|
||||
'required' => false,
|
||||
'disabled' => $build_request->getProject()->getBuildPart() === null,
|
||||
'disabled' => !$build_request->getProject()->getBuildPart() instanceof \App\Entity\Parts\Part,
|
||||
]);
|
||||
|
||||
if ($build_request->getProject()->getBuildPart()) {
|
||||
if ($build_request->getProject()->getBuildPart() instanceof \App\Entity\Parts\Part) {
|
||||
$form->add('buildsPartLot', PartLotSelectType::class, [
|
||||
'label' => 'project.build.builds_part_lot',
|
||||
'required' => false,
|
||||
|
|
|
@ -36,12 +36,9 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
*/
|
||||
class CurrencyEntityType extends StructuralEntityType
|
||||
{
|
||||
protected ?string $base_currency;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, NodesListBuilder $builder, TranslatorInterface $translator, StructuralEntityChoiceHelper $choiceHelper, ?string $base_currency)
|
||||
public function __construct(EntityManagerInterface $em, NodesListBuilder $builder, TranslatorInterface $translator, StructuralEntityChoiceHelper $choiceHelper, protected ?string $base_currency)
|
||||
{
|
||||
parent::__construct($em, $builder, $translator, $choiceHelper);
|
||||
$this->base_currency = $base_currency;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
@ -56,11 +53,7 @@ class CurrencyEntityType extends StructuralEntityType
|
|||
// This options allows you to override the currency shown for the null value
|
||||
$resolver->setDefault('base_currency', null);
|
||||
|
||||
$resolver->setDefault('choice_attr', function (Options $options) {
|
||||
return function ($choice) use ($options) {
|
||||
return $this->choice_helper->generateChoiceAttrCurrency($choice, $options);
|
||||
};
|
||||
});
|
||||
$resolver->setDefault('choice_attr', fn(Options $options) => fn($choice) => $this->choice_helper->generateChoiceAttrCurrency($choice, $options));
|
||||
|
||||
$resolver->setDefault('empty_message', function (Options $options) {
|
||||
//By default, we use the global base currency:
|
||||
|
|
|
@ -34,22 +34,15 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
class StructuralEntityChoiceHelper
|
||||
{
|
||||
|
||||
private AttachmentURLGenerator $attachmentURLGenerator;
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(AttachmentURLGenerator $attachmentURLGenerator, TranslatorInterface $translator)
|
||||
public function __construct(private readonly AttachmentURLGenerator $attachmentURLGenerator, private readonly TranslatorInterface $translator)
|
||||
{
|
||||
$this->attachmentURLGenerator = $attachmentURLGenerator;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the choice attributes for the given AbstractStructuralDBElement.
|
||||
* @param AbstractNamedDBElement $choice
|
||||
* @param Options|array $options
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function generateChoiceAttr(AbstractNamedDBElement $choice, $options): array
|
||||
public function generateChoiceAttr(AbstractNamedDBElement $choice, \Symfony\Component\OptionsResolver\Options|array $options): array
|
||||
{
|
||||
$tmp = [
|
||||
'data-level' => 0,
|
||||
|
@ -69,19 +62,19 @@ class StructuralEntityChoiceHelper
|
|||
$level = $choice->getLevel();
|
||||
/** @var AbstractStructuralDBElement|null $parent */
|
||||
$parent = $options['subentities_of'] ?? null;
|
||||
if (null !== $parent) {
|
||||
if ($parent instanceof \App\Entity\Base\AbstractStructuralDBElement) {
|
||||
$level -= $parent->getLevel() - 1;
|
||||
}
|
||||
|
||||
$tmp += [
|
||||
'data-level' => $level,
|
||||
'data-parent' => $choice->getParent() ? $choice->getParent()->getFullPath() : null,
|
||||
'data-parent' => $choice->getParent() instanceof \App\Entity\Base\AbstractStructuralDBElement ? $choice->getParent()->getFullPath() : null,
|
||||
'data-path' => $choice->getFullPath('->'),
|
||||
];
|
||||
}
|
||||
|
||||
if ($choice instanceof HasMasterAttachmentInterface) {
|
||||
$tmp['data-image'] = $choice->getMasterPictureAttachment() ?
|
||||
$tmp['data-image'] = $choice->getMasterPictureAttachment() instanceof \App\Entity\Attachments\Attachment ?
|
||||
$this->attachmentURLGenerator->getThumbnailURL($choice->getMasterPictureAttachment(),
|
||||
'thumbnail_xs')
|
||||
: null
|
||||
|
@ -97,37 +90,21 @@ class StructuralEntityChoiceHelper
|
|||
|
||||
/**
|
||||
* Generates the choice attributes for the given AbstractStructuralDBElement.
|
||||
* @param Currency $choice
|
||||
* @param Options|array $options
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function generateChoiceAttrCurrency(Currency $choice, $options): array
|
||||
public function generateChoiceAttrCurrency(Currency $choice, \Symfony\Component\OptionsResolver\Options|array $options): array
|
||||
{
|
||||
$tmp = $this->generateChoiceAttr($choice, $options);
|
||||
$symbol = empty($choice->getIsoCode()) ? null : Currencies::getSymbol($choice->getIsoCode());
|
||||
$tmp['data-short'] = $options['short'] ? $symbol : $choice->getName();
|
||||
|
||||
if(!empty($choice->getIsoCode())) {
|
||||
$symbol = Currencies::getSymbol($choice->getIsoCode());
|
||||
} else {
|
||||
$symbol = null;
|
||||
}
|
||||
|
||||
if ($options['short']) {
|
||||
$tmp['data-short'] = $symbol;
|
||||
} else {
|
||||
$tmp['data-short'] = $choice->getName();
|
||||
}
|
||||
|
||||
$tmp += [
|
||||
return $tmp + [
|
||||
'data-symbol' => $symbol,
|
||||
];
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the choice label for the given AbstractStructuralDBElement.
|
||||
* @param AbstractNamedDBElement $choice
|
||||
* @return string
|
||||
*/
|
||||
public function generateChoiceLabel(AbstractNamedDBElement $choice): string
|
||||
{
|
||||
|
@ -136,12 +113,10 @@ class StructuralEntityChoiceHelper
|
|||
|
||||
/**
|
||||
* Returns the choice value for the given AbstractStructuralDBElement.
|
||||
* @param AbstractNamedDBElement|null $element
|
||||
* @return string|int|null
|
||||
*/
|
||||
public function generateChoiceValue(?AbstractNamedDBElement $element)
|
||||
public function generateChoiceValue(?AbstractNamedDBElement $element): string|int|null
|
||||
{
|
||||
if ($element === null) {
|
||||
if (!$element instanceof \App\Entity\Base\AbstractNamedDBElement) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -162,10 +137,6 @@ class StructuralEntityChoiceHelper
|
|||
return $element->getID();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractDBElement $element
|
||||
* @return string|null
|
||||
*/
|
||||
public function generateGroupBy(AbstractDBElement $element): ?string
|
||||
{
|
||||
//Show entities that are not added to DB yet separately from other entities
|
||||
|
|
|
@ -28,17 +28,10 @@ use Symfony\Component\OptionsResolver\Options;
|
|||
|
||||
class StructuralEntityChoiceLoader extends AbstractChoiceLoader
|
||||
{
|
||||
private Options $options;
|
||||
private NodesListBuilder $builder;
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
private ?string $additional_element = null;
|
||||
|
||||
public function __construct(Options $options, NodesListBuilder $builder, EntityManagerInterface $entityManager)
|
||||
public function __construct(private readonly Options $options, private readonly NodesListBuilder $builder, private readonly EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->options = $options;
|
||||
$this->builder = $builder;
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
protected function loadChoices(): iterable
|
||||
|
|
|
@ -42,32 +42,28 @@ class MasterPictureAttachmentType extends AbstractType
|
|||
$resolver->setDefaults([
|
||||
'filter' => 'picture',
|
||||
'choice_translation_domain' => false,
|
||||
'choice_attr' => static function (Options $options) {
|
||||
return static function ($choice, $key, $value) use ($options) {
|
||||
/** @var Attachment $choice */
|
||||
$tmp = ['data-subtext' => $choice->getFilename() ?? 'URL'];
|
||||
'choice_attr' => static fn(Options $options) => static function ($choice, $key, $value) use ($options) {
|
||||
/** @var Attachment $choice */
|
||||
$tmp = ['data-subtext' => $choice->getFilename() ?? 'URL'];
|
||||
|
||||
if ('picture' === $options['filter'] && !$choice->isPicture()) {
|
||||
$tmp += ['disabled' => 'disabled'];
|
||||
} elseif ('3d_model' === $options['filter'] && !$choice->is3DModel()) {
|
||||
$tmp += ['disabled' => 'disabled'];
|
||||
}
|
||||
if ('picture' === $options['filter'] && !$choice->isPicture()) {
|
||||
$tmp += ['disabled' => 'disabled'];
|
||||
} elseif ('3d_model' === $options['filter'] && !$choice->is3DModel()) {
|
||||
$tmp += ['disabled' => 'disabled'];
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
};
|
||||
return $tmp;
|
||||
},
|
||||
'choice_label' => 'name',
|
||||
'choice_loader' => static function (Options $options) {
|
||||
return new CallbackChoiceLoader(
|
||||
static function () use ($options) {
|
||||
$entity = $options['entity'];
|
||||
if (!$entity instanceof AttachmentContainingDBElement) {
|
||||
throw new RuntimeException('$entity must have Attachments! (be of type AttachmentContainingDBElement)');
|
||||
}
|
||||
'choice_loader' => static fn(Options $options) => new CallbackChoiceLoader(
|
||||
static function () use ($options) {
|
||||
$entity = $options['entity'];
|
||||
if (!$entity instanceof AttachmentContainingDBElement) {
|
||||
throw new RuntimeException('$entity must have Attachments! (be of type AttachmentContainingDBElement)');
|
||||
}
|
||||
|
||||
return $entity->getAttachments()->toArray();
|
||||
});
|
||||
},
|
||||
return $entity->getAttachments()->toArray();
|
||||
}),
|
||||
]);
|
||||
|
||||
$resolver->setAllowedValues('filter', ['', 'picture', '3d_model']);
|
||||
|
|
|
@ -43,17 +43,11 @@ class PartLotSelectType extends AbstractType
|
|||
|
||||
$resolver->setDefaults([
|
||||
'class' => PartLot::class,
|
||||
'choice_label' => ChoiceList::label($this, static function (PartLot $part_lot) {
|
||||
return ($part_lot->getStorageLocation() ? $part_lot->getStorageLocation()->getFullPath() : '')
|
||||
. ' (' . $part_lot->getName() . '): ' . $part_lot->getAmount();
|
||||
}),
|
||||
'query_builder' => function (Options $options) {
|
||||
return static function (EntityRepository $er) use ($options) {
|
||||
return $er->createQueryBuilder('l')
|
||||
->where('l.part = :part')
|
||||
->setParameter('part', $options['part']);
|
||||
};
|
||||
}
|
||||
'choice_label' => ChoiceList::label($this, static fn(PartLot $part_lot): string => ($part_lot->getStorageLocation() instanceof \App\Entity\Parts\Storelocation ? $part_lot->getStorageLocation()->getFullPath() : '')
|
||||
. ' (' . $part_lot->getName() . '): ' . $part_lot->getAmount()),
|
||||
'query_builder' => fn(Options $options) => static fn(EntityRepository $er) => $er->createQueryBuilder('l')
|
||||
->where('l.part = :part')
|
||||
->setParameter('part', $options['part'])
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -19,18 +19,8 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|||
|
||||
class PartSelectType extends AbstractType implements DataMapperInterface
|
||||
{
|
||||
private UrlGeneratorInterface $urlGenerator;
|
||||
private EntityManagerInterface $em;
|
||||
private PartPreviewGenerator $previewGenerator;
|
||||
private AttachmentURLGenerator $attachmentURLGenerator;
|
||||
|
||||
public function __construct(UrlGeneratorInterface $urlGenerator, EntityManagerInterface $em, PartPreviewGenerator $previewGenerator,
|
||||
AttachmentURLGenerator $attachmentURLGenerator)
|
||||
public function __construct(private readonly UrlGeneratorInterface $urlGenerator, private readonly EntityManagerInterface $em, private readonly PartPreviewGenerator $previewGenerator, private readonly AttachmentURLGenerator $attachmentURLGenerator)
|
||||
{
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->em = $em;
|
||||
$this->previewGenerator = $previewGenerator;
|
||||
$this->attachmentURLGenerator = $attachmentURLGenerator;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
|
@ -96,10 +86,10 @@ class PartSelectType extends AbstractType implements DataMapperInterface
|
|||
$resolver->setDefaults([
|
||||
//Prefill the selected choice with the needed data, so the user can see it without an additional Ajax request
|
||||
'choice_attr' => ChoiceList::attr($this, function (?Part $part) {
|
||||
if($part) {
|
||||
if($part instanceof \App\Entity\Parts\Part) {
|
||||
//Determine the picture to show:
|
||||
$preview_attachment = $this->previewGenerator->getTablePreviewAttachment($part);
|
||||
if ($preview_attachment !== null) {
|
||||
if ($preview_attachment instanceof \App\Entity\Attachments\Attachment) {
|
||||
$preview_url = $this->attachmentURLGenerator->getThumbnailURL($preview_attachment,
|
||||
'thumbnail_sm');
|
||||
} else {
|
||||
|
@ -107,10 +97,10 @@ class PartSelectType extends AbstractType implements DataMapperInterface
|
|||
}
|
||||
}
|
||||
|
||||
return $part ? [
|
||||
return $part instanceof \App\Entity\Parts\Part ? [
|
||||
'data-description' => mb_strimwidth($part->getDescription(), 0, 127, '...'),
|
||||
'data-category' => $part->getCategory() ? $part->getCategory()->getName() : '',
|
||||
'data-footprint' => $part->getFootprint() ? $part->getFootprint()->getName() : '',
|
||||
'data-category' => $part->getCategory() instanceof \App\Entity\Parts\Category ? $part->getCategory()->getName() : '',
|
||||
'data-footprint' => $part->getFootprint() instanceof \App\Entity\Parts\Footprint ? $part->getFootprint()->getName() : '',
|
||||
'data-image' => $preview_url,
|
||||
] : [];
|
||||
})
|
||||
|
|
|
@ -48,18 +48,13 @@ class RichTextEditorType extends AbstractType
|
|||
|
||||
protected function optionsToAttrArray(array $options): array
|
||||
{
|
||||
$tmp = [];
|
||||
|
||||
//Set novalidate attribute, or we will get problems that form can not be submitted as textarea is not focusable
|
||||
$tmp['novalidate'] = 'novalidate';
|
||||
|
||||
$tmp['data-mode'] = $options['mode'];
|
||||
|
||||
//Add our data-controller element to the textarea
|
||||
$tmp['data-controller'] = 'elements--ckeditor';
|
||||
|
||||
|
||||
return $tmp;
|
||||
return [
|
||||
//Set novalidate attribute, or we will get problems that form can not be submitted as textarea is not focusable
|
||||
'novalidate' => 'novalidate',
|
||||
'data-mode' => $options['mode'],
|
||||
//Add our data-controller element to the textarea
|
||||
'data-controller' => 'elements--ckeditor',
|
||||
];
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
|
|
|
@ -38,11 +38,8 @@ use Traversable;
|
|||
|
||||
final class SIUnitType extends AbstractType implements DataMapperInterface
|
||||
{
|
||||
protected SIFormatter $si_formatter;
|
||||
|
||||
public function __construct(SIFormatter $SIFormatter)
|
||||
public function __construct(protected SIFormatter $si_formatter)
|
||||
{
|
||||
$this->si_formatter = $SIFormatter;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
@ -91,7 +88,7 @@ final class SIUnitType extends AbstractType implements DataMapperInterface
|
|||
$resolver->setDefaults([
|
||||
'min' => 0,
|
||||
'max' => '',
|
||||
'step' => static function (Options $options) {
|
||||
'step' => static function (Options $options): int|string {
|
||||
if (true === $options['is_integer']) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -138,7 +135,7 @@ final class SIUnitType extends AbstractType implements DataMapperInterface
|
|||
|
||||
//Check if we need to make this thing small
|
||||
if (isset($options['attr']['class'])) {
|
||||
$view->vars['sm'] = str_contains($options['attr']['class'], 'form-control-sm');
|
||||
$view->vars['sm'] = str_contains((string) $options['attr']['class'], 'form-control-sm');
|
||||
}
|
||||
|
||||
$view->vars['unit'] = $options['unit'];
|
||||
|
|
|
@ -44,21 +44,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||
*/
|
||||
class StructuralEntityType extends AbstractType
|
||||
{
|
||||
protected EntityManagerInterface $em;
|
||||
protected TranslatorInterface $translator;
|
||||
protected StructuralEntityChoiceHelper $choice_helper;
|
||||
|
||||
/**
|
||||
* @var NodesListBuilder
|
||||
*/
|
||||
protected NodesListBuilder $builder;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, NodesListBuilder $builder, TranslatorInterface $translator, StructuralEntityChoiceHelper $choice_helper)
|
||||
public function __construct(protected EntityManagerInterface $em, protected NodesListBuilder $builder, protected TranslatorInterface $translator, protected StructuralEntityChoiceHelper $choice_helper)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->builder = $builder;
|
||||
$this->translator = $translator;
|
||||
$this->choice_helper = $choice_helper;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
@ -81,11 +68,7 @@ class StructuralEntityType extends AbstractType
|
|||
});
|
||||
|
||||
$builder->addModelTransformer(new CallbackTransformer(
|
||||
function ($value) use ($options) {
|
||||
return $this->modelTransform($value, $options);
|
||||
}, function ($value) use ($options) {
|
||||
return $this->modelReverseTransform($value, $options);
|
||||
}));
|
||||
fn($value) => $this->modelTransform($value, $options), fn($value) => $this->modelReverseTransform($value, $options)));
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
@ -96,25 +79,11 @@ class StructuralEntityType extends AbstractType
|
|||
'show_fullpath_in_subtext' => true, //When this is enabled, the full path will be shown in subtext
|
||||
'subentities_of' => null, //Only show entities with the given parent class
|
||||
'disable_not_selectable' => false, //Disable entries with not selectable property
|
||||
'choice_value' => function (?AbstractNamedDBElement $element) {
|
||||
return $this->choice_helper->generateChoiceValue($element);
|
||||
}, //Use the element id as option value and for comparing items
|
||||
'choice_loader' => function (Options $options) {
|
||||
return new StructuralEntityChoiceLoader($options, $this->builder, $this->em);
|
||||
},
|
||||
'choice_label' => function (Options $options) {
|
||||
return function ($choice, $key, $value) {
|
||||
return $this->choice_helper->generateChoiceLabel($choice);
|
||||
};
|
||||
},
|
||||
'choice_attr' => function (Options $options) {
|
||||
return function ($choice, $key, $value) use ($options) {
|
||||
return $this->choice_helper->generateChoiceAttr($choice, $options);
|
||||
};
|
||||
},
|
||||
'group_by' => function (AbstractNamedDBElement $element) {
|
||||
return $this->choice_helper->generateGroupBy($element);
|
||||
},
|
||||
'choice_value' => fn(?AbstractNamedDBElement $element) => $this->choice_helper->generateChoiceValue($element), //Use the element id as option value and for comparing items
|
||||
'choice_loader' => fn(Options $options) => new StructuralEntityChoiceLoader($options, $this->builder, $this->em),
|
||||
'choice_label' => fn(Options $options) => fn($choice, $key, $value) => $this->choice_helper->generateChoiceLabel($choice),
|
||||
'choice_attr' => fn(Options $options) => fn($choice, $key, $value) => $this->choice_helper->generateChoiceAttr($choice, $options),
|
||||
'group_by' => fn(AbstractNamedDBElement $element) => $this->choice_helper->generateGroupBy($element),
|
||||
'choice_translation_domain' => false, //Don't translate the entity names
|
||||
]);
|
||||
|
||||
|
|
|
@ -26,11 +26,8 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
|
||||
class ThemeChoiceType extends AbstractType
|
||||
{
|
||||
private array $available_themes;
|
||||
|
||||
public function __construct(array $available_themes)
|
||||
public function __construct(private readonly array $available_themes)
|
||||
{
|
||||
$this->available_themes = $available_themes;
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
|
@ -42,9 +39,7 @@ class ThemeChoiceType extends AbstractType
|
|||
{
|
||||
$resolver->setDefaults([
|
||||
'choices' => $this->available_themes,
|
||||
'choice_label' => static function ($entity, $key, $value) {
|
||||
return $value;
|
||||
},
|
||||
'choice_label' => static fn($entity, $key, $value) => $value,
|
||||
'choice_translation_domain' => false,
|
||||
'placeholder' => 'user_settings.theme.placeholder'
|
||||
]);
|
||||
|
|
|
@ -147,17 +147,11 @@ final class TriStateCheckboxType extends AbstractType implements DataTransformer
|
|||
*/
|
||||
public function reverseTransform($value)
|
||||
{
|
||||
switch ($value) {
|
||||
case 'true':
|
||||
return true;
|
||||
case 'false':
|
||||
return false;
|
||||
case 'indeterminate':
|
||||
case 'null':
|
||||
case '':
|
||||
return null;
|
||||
default:
|
||||
throw new InvalidArgumentException('Invalid value encountered!: '.$value);
|
||||
}
|
||||
return match ($value) {
|
||||
'true' => true,
|
||||
'false' => false,
|
||||
'indeterminate', 'null', '' => null,
|
||||
default => throw new InvalidArgumentException('Invalid value encountered!: '.$value),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,11 +32,7 @@ class UserSelectType extends AbstractType
|
|||
{
|
||||
$resolver->setDefaults([
|
||||
'class' => User::class,
|
||||
'choice_label' => function (Options $options) {
|
||||
return function (User $choice, $key, $value) {
|
||||
return $choice->getFullName(true);
|
||||
};
|
||||
},
|
||||
'choice_label' => fn(Options $options) => fn(User $choice, $key, $value) => $choice->getFullName(true),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,11 +48,8 @@ use Symfony\Component\Validator\Constraints\Length;
|
|||
|
||||
class UserAdminForm extends AbstractType
|
||||
{
|
||||
protected \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security)
|
||||
public function __construct(protected \Symfony\Bundle\SecurityBundle\Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
|
|
@ -44,13 +44,8 @@ use Symfony\Component\Validator\Constraints\File;
|
|||
|
||||
class UserSettingsType extends AbstractType
|
||||
{
|
||||
protected \Symfony\Bundle\SecurityBundle\Security $security;
|
||||
protected bool $demo_mode;
|
||||
|
||||
public function __construct(\Symfony\Bundle\SecurityBundle\Security $security, bool $demo_mode)
|
||||
public function __construct(protected \Symfony\Bundle\SecurityBundle\Security $security, protected bool $demo_mode)
|
||||
{
|
||||
$this->security = $security;
|
||||
$this->demo_mode = $demo_mode;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue