Skip to content
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

Merged

Conversation

CoderMaggie
Copy link
Member

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;
Copy link
Contributor

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.

@@ -44,6 +45,8 @@ function __construct($dataClass, array $validationGroups, $subject)
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$currentArchetype = $builder->getForm()->getData();
Copy link
Member

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. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed! :)

->createQueryBuilder('parentArchetype')
->where('parentArchetype.id != :id')
->setParameter('id', $currentArchetype->getId())
;
Copy link
Member

Choose a reason for hiding this comment

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

cs

use Symfony\Component\Form\FormEvents;


/**
Copy link
Member

Choose a reason for hiding this comment

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

Extra blank line.

@pjedrzejewski
Copy link
Member

👍

{
$currentArchetype = $event->getData();
if (!$currentArchetype instanceof ArchetypeInterface) {
throw new UnexpectedTypeException($currentArchetype, 'Sylius\Component\Archetype\Model\ArchetypeInterface');
Copy link
Contributor

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

Copy link
Member

Choose a reason for hiding this comment

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

👍

'property' => 'name'
);

if (null != $currentArchetype->getId()) {
Copy link
Contributor

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?

Copy link
Member Author

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.

pjedrzejewski pushed a commit that referenced this pull request Oct 19, 2015
[Archetype] Parent archetype choices list should not contain current archetype
@pjedrzejewski pjedrzejewski merged commit 061a435 into Sylius:master Oct 19, 2015
@pjedrzejewski
Copy link
Member

Thank you Magda! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants