Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow

StackOverflow Logo StackOverflow Logo

StackOverflow Navigation

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Add group
  • Feed
  • User Profile
  • Communities
  • Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
Home/ Questions/Q 516
Next

StackOverflow Latest Questions

Saralyn
  • 0
  • 0
SaralynBegginer
Asked: February 7, 20252025-02-07T11:59:38+00:00 2025-02-07T11:59:38+00:00In: PHP

php – How to keep selected value in Symfony EntityType if value was deleted by softdeletable?

  • 0
  • 0
php – How to keep selected value in Symfony EntityType if value was deleted by softdeletable?

First of all, I use Gedmo’s softdeletable to manage deleted entities. Also I have my own EntityField:

namespace App\Form\Fields;

use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;

class EntityField extends AbstractType
{
    public function configureOptions(OptionsResolver $resolver): void
    {
        parent::configureOptions($resolver);

        // some additional configuration

        $resolver->setDefaults([
            'query_builder' => function (EntityRepository $er): QueryBuilder {
                return $er->createQueryBuilder('entity')
                    ->andWhere('entity.deletedAt IS NULL');
            },
        ]);
    }

    public function getParent(): string
    {
        return EntityType::class;
    }
}

As you can see, I don’t use softdeleteable filter in Doctrine, but instead I use custom query_builder in my EntityField.

It works fine as long as I’ve softdeleted entity thas has been already used.

E.g. I have User, File and FileType entities, User has collection of Files and File has FileType. I’ve softdeleted some FileType and for me it means I don’t want to create new Files of this FileType, but all existing Files of this FileType are still legal and have to be properly displayed in forms. “Properly” means, in this case, that if I render File form and this exact file has deleted FileType, the select must have this FileType. But now I have no selected value in this field and it loks like “there is no selected file type for this file” that is not.

I tried to modify query_builder in FormEvents::PRE_SET_DATA event and add the value from the database, but it looks like list of choises is generated before this event, because I can see updated query_builder in the form, but the real query corresponds to unmodified query_buider.

There are buildView and finishView methods, but I don’t think it’s a good idea to use them, because in this case I need to manually modify form attributes.

So, is there a “Symfony way” to do that? Maybe I forgot some form options?

0
  • 0 0 Answers
  • 83 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • Popular
  • Answers
  • W3spoint99

    What is Physics? Definition, History, Importance, Scope (Class 11)

    • 1 Answer
  • W3spoint99

    The Living World – Introduction, Classification, Characteristics, FAQs (Class 11 ...

    • 1 Answer
  • W3spoint99

    Explain - Biological Classification (Class 11 - Biology)

    • 1 Answer
  • Saralyn
    Saralyn added an answer When Humans look at their childhood pictures, the first thing… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Previously, length was measured using units such as the length… January 17, 2025 at 3:25 pm
  • Saralyn
    Saralyn added an answer Measurement forms the fundamental principle to various other branches of… January 17, 2025 at 3:25 pm

Related Questions

  • Reading fancy apostrophe PHP [duplicate]

    • 0 Answers
  • Unable to send mail via PHPMailer [SMTP->Error: Password not accepted ...

    • 0 Answers
  • Concerns when migrating from PHP 5.6 to 8.4 [closed]

    • 0 Answers
  • Laravel Auth::attempt() error: "Unknown column 'password'" when using a custom ...

    • 0 Answers
  • Core PHP cURL - header origin pass null value

    • 0 Answers

Trending Tags

biology class 11 forces how physics relates to other sciences interdisciplinary science learn mathematics math sets tutorial null sets physics physics and astronomy physics and biology physics and chemistry physics applications science science connections science education sets in mathematics set theory basics types of sets types of sets explained

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

  • About US
  • Privacy Policy
  • Questions
  • Recent Questions
  • Web Stories

© 2025 WikiQuora.Com. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.