mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Prevent adding a zone of type zone to itself
This commit is contained in:
parent
4bb2b6602c
commit
2cd7b2d96f
4 changed files with 37 additions and 5 deletions
|
|
@ -61,3 +61,9 @@ Feature: Editing a zone
|
|||
Given the store has a zone "European Union" with code "EU"
|
||||
When I want to modify the zone named "European Union"
|
||||
Then the code field should be disabled
|
||||
|
||||
@ui
|
||||
Scenario: Not seeing zone itself in member select when editing a zone of type zone
|
||||
Given the store has a zone "European Union" with code "EU"
|
||||
When I want to modify the zone named "European Union"
|
||||
Then I can not add a zone "European Union"
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
namespace Sylius\Behat\Context\Ui\Admin;
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
use Behat\Mink\Exception\ElementNotFoundException;
|
||||
use Sylius\Behat\NotificationType;
|
||||
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
|
||||
use Sylius\Behat\Page\Admin\Zone\CreatePageInterface;
|
||||
|
|
@ -354,4 +355,16 @@ final class ManagingZonesContext implements Context
|
|||
|
||||
Assert::true($this->updatePage->hasMember($zoneMember));
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^I can not add a(?: country| province| zone) "([^"]+)"$/
|
||||
*/
|
||||
public function iCanNotAddAZoneMember($name)
|
||||
{
|
||||
$member = null;
|
||||
try {
|
||||
$member = $this->createPage->chooseMember($name);
|
||||
} catch (ElementNotFoundException $exception) {}
|
||||
Assert::isEmpty($member);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,8 +53,13 @@ final class ZoneCodeChoiceType extends AbstractType
|
|||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'choice_filter' => null,
|
||||
'choices' => function (Options $options) {
|
||||
return $this->zoneRepository->findAll();
|
||||
$zones = $this->zoneRepository->findAll();
|
||||
if ($options['choice_filter']) {
|
||||
$zones = array_filter($zones, $options['choice_filter']);
|
||||
}
|
||||
return $zones;
|
||||
},
|
||||
'choice_value' => 'code',
|
||||
'choice_label' => 'name',
|
||||
|
|
|
|||
|
|
@ -75,12 +75,20 @@ final class ZoneType extends AbstractResourceType
|
|||
/** @var ZoneInterface $zone */
|
||||
$zone = $event->getData();
|
||||
|
||||
$entryOptions = [
|
||||
'entry_type' => $this->getZoneMemberEntryType($zone->getType()),
|
||||
'entry_options' => $this->getZoneMemberEntryOptions($zone->getType()),
|
||||
];
|
||||
|
||||
if ($zone->getType() === ZoneInterface::TYPE_ZONE) {
|
||||
$entryOptions['entry_options']['choice_filter'] = function(ZoneInterface $subZone) use ($zone){
|
||||
return $zone->getId() !== $subZone->getId();
|
||||
};
|
||||
}
|
||||
|
||||
$event->getForm()->add('members', CollectionType::class, [
|
||||
'entry_type' => ZoneMemberType::class,
|
||||
'entry_options' => [
|
||||
'entry_type' => $this->getZoneMemberEntryType($zone->getType()),
|
||||
'entry_options' => $this->getZoneMemberEntryOptions($zone->getType()),
|
||||
],
|
||||
'entry_options' => $entryOptions,
|
||||
'button_add_label' => 'sylius.form.zone.add_member',
|
||||
'allow_add' => true,
|
||||
'allow_delete' => true,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue