-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Archetype] Parent archetype choices list should not contain current archetype #3381
[Archetype] Parent archetype choices list should not contain current archetype #3381
Conversation
CoderMaggie
commented
Oct 2, 2015
Q | A |
---|---|
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Fixed tickets | #3359 |
License | MIT |
@@ -11,6 +11,7 @@ | |||
|
|||
namespace Sylius\Bundle\ArchetypeBundle\Form\Type; | |||
|
|||
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be interface to not blocking people using ODM.
f812012
to
d5633ee
Compare
@@ -44,6 +45,8 @@ function __construct($dataClass, array $validationGroups, $subject) | |||
*/ | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$currentArchetype = $builder->getForm()->getData(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do a listener, cause it only works when you pass the data when creating the form. If someone calls setData
later, it will not be taken into account. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed! :)
d5633ee
to
9432f57
Compare
->createQueryBuilder('parentArchetype') | ||
->where('parentArchetype.id != :id') | ||
->setParameter('id', $currentArchetype->getId()) | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cs
9432f57
to
a235155
Compare
use Symfony\Component\Form\FormEvents; | ||
|
||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line.
👍 |
a235155
to
6e6a01f
Compare
{ | ||
$currentArchetype = $event->getData(); | ||
if (!$currentArchetype instanceof ArchetypeInterface) { | ||
throw new UnexpectedTypeException($currentArchetype, 'Sylius\Component\Archetype\Model\ArchetypeInterface'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hardcoded string we should use ArchetypeInterface::class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
6e6a01f
to
41a51ca
Compare
'property' => 'name' | ||
); | ||
|
||
if (null != $currentArchetype->getId()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it break anything if we remove this if
statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes :) We need to check if the current archetype already has ID, because if it doesn't (for instance while creating new archetype) the query for possible parent archetype is failing because it uses Null in the where statement.
41a51ca
to
6f934a3
Compare
[Archetype] Parent archetype choices list should not contain current archetype
Thank you Magda! 👍 |