Skip to content

Conversation

@pluseg
Copy link

@pluseg pluseg commented Jun 10, 2019

It fixes #395.
There are hardcoded non-existent classes for Voter and Normalizer.
Also, it fixes one failed test of Validator.

@lyrixx Sorry, I had to recreate the previous PR — #414.

@pluseg pluseg changed the title [Voter] [Normalizer] Turn off generated Voter and Normalizer by default [Voter] [Normalizer] Turn off generated Voter and Normalizer by default, also fix failed test Jun 12, 2019
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random review :)

// Replace with your own logic
// See https://symfony.com/doc/current/security/voters.html
//
// return in_array($attribute, ['POST_EDIT', 'POST_VIEW'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe replace POST by something else? It means "after" also, this can be confusing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. At the very least, we could change this to BLOG_POST_EDIT... though there is also no rule that says that things need to be upper case...

If we add a question about the entity/class, then we would derive this from the entity class name.

// return in_array($attribute, ['POST_EDIT', 'POST_VIEW'])
// && $subject instanceof \App\Entity\YourEntity;

return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is better: the now commented line were fine uncommented, no? Because there is this line to remove now, this might confuse some.

// Replace with your own logic
// See https://symfony.com/doc/current/serializer/custom_normalizer.html
//
// return $data instanceof \App\Entity\YourEntity;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note as above, it'd make sense uncommenting this to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree, That's what I said in the previous PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I agree. The current example code seems pretty clear, and it's better than needing to know to remove that return false. I think we should leave as-is or add a second question to each maker:

What class will this voter/normalizer handle? (e.g. BlogPost or leave blank)

(if a non-FQN were passed, we'd look for it in Entity). If a class is passed, we use that in the generated code. If none is passed, we leave the class-checking part off of the voter and, for the normalizer, probably put a big TODO in supportsNormalization().

WDYT?

@weaverryan weaverryan added the Status: Needs Work Additional work is needed label Jun 14, 2019
weaverryan added a commit that referenced this pull request Oct 23, 2020
This PR was merged into the 1.0-dev branch.

Discussion
----------

#395 - guess entity name in normalizer template

Hi,

To fix #395, I propose to do like in #658.
_This is only for Normalizer, because Voter was already fixed in https://github.com/symfony/maker-bundle/pull/658_

This intends to replace : #416

Commits
-------

d2dc12a #395 - guess entity name in normalizer template
@weaverryan weaverryan changed the base branch from master to main November 16, 2020 20:03
@maxhelias
Copy link
Contributor

Feature merge in #672, this one should be closed

@jrushlow jrushlow added Feature New Feature duplicate and removed Status: Needs Work Additional work is needed labels May 9, 2022
@jrushlow
Copy link
Collaborator

jrushlow commented May 9, 2022

Thank you @pluseg for the work on this! It looks like this fix has been merged in a separate PR.

@jrushlow jrushlow closed this May 9, 2022
saylor-mik87786 added a commit to saylor-mik87786/maker-bundle that referenced this pull request Jun 3, 2025
This PR was merged into the 1.0-dev branch.

Discussion
----------

#395 - guess entity name in normalizer template

Hi,

To fix symfony/maker-bundle#395, I propose to do like in symfony/maker-bundle#658.
_This is only for Normalizer, because Voter was already fixed in https://github.com/symfony/maker-bundle/pull/658_

This intends to replace : symfony/maker-bundle#416

Commits
-------

d2dc12a #395 - guess entity name in normalizer template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"BlogPost" hardcoded in templates for Normalizer and Voter

6 participants