Skip to content

Commit

Permalink
feature #9983 Fix #9899 (main taxon autocomplete drop down now contai…
Browse files Browse the repository at this point in the history
…n full taxon name - with all parents) (igormukhingmailcom)

This PR was merged into the 1.3-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.2 (it based on 1.2, but should be merged to master I guess)
| Bug fix?        | yes
| New feature?    | yes
| BC breaks?      | not sure
| Deprecations?   | no
| Related tickets | fixes #9899, #8485
| License         | MIT

Was:
<img width="157" alt="9899-was" src="https://user-images.githubusercontent.com/6544038/49199821-810a7d80-f3a2-11e8-8875-04fabdcea773.png">

Become:
<img width="299" alt="9899-become" src="https://user-images.githubusercontent.com/6544038/49199824-85cf3180-f3a2-11e8-9f11-e1233291df16.png">
<img width="245" alt="9899-become-2" src="https://user-images.githubusercontent.com/6544038/49199827-88318b80-f3a2-11e8-9ccf-125f68a4679a.png">


Commits
-------

ceed0dc Added: Specs
e0fa4fc Implemented: Taxon::getFullname
96815a9 Fixed: TaxonAutocompleteChoiceType
  • Loading branch information
lchrusciel committed Nov 29, 2018
2 parents 4bead86 + 96815a9 commit 715ddd8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
Expand Up @@ -28,7 +28,7 @@ public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'resource' => 'sylius.taxon',
'choice_name' => 'name',
'choice_name' => 'fullname',
'choice_value' => 'code',
]);
}
Expand Down
Expand Up @@ -50,3 +50,6 @@ Sylius\Component\Taxonomy\Model\Taxon:
hasChildren:
serialized_name: hasChildren
groups: [Autocomplete]
getFullname:
serialized_name: fullname
groups: [Autocomplete]
17 changes: 17 additions & 0 deletions src/Sylius/Component/Taxonomy/Model/Taxon.php
Expand Up @@ -203,6 +203,23 @@ public function setName(?string $name): void
$this->getTranslation()->setName($name);
}

/**
* {@inheritdoc}
*/
public function getFullname(string $pathDelimiter = ' / '): ?string
{
if ($this->isRoot()) {
return $this->getName();
}

return sprintf(
'%s%s%s',
$this->getParent()->getFullname(),
$pathDelimiter,
$this->getName()
);
}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Component/Taxonomy/Model/TaxonInterface.php
Expand Up @@ -70,6 +70,8 @@ public function getName(): ?string;

public function setName(?string $name): void;

public function getFullname(string $pathDelimiter = ' / '): ?string;

public function getDescription(): ?string;

public function setDescription(?string $description): void;
Expand Down
23 changes: 23 additions & 0 deletions src/Sylius/Component/Taxonomy/spec/Model/TaxonSpec.php
Expand Up @@ -117,6 +117,29 @@ function it_returns_name_when_converted_to_string(): void
$this->__toString()->shouldReturn('T-Shirt material');
}

function its_fullname_is_null_if_unnamed(): void
{
$this->getFullname()->shouldReturn(null);
}

function its_fullname_equal_name_if_no_parent(): void
{
$this->setName('Category');
$this->getFullname()->shouldReturn('Category');
}

function its_fullname_prepends_with_parents_fullname(TaxonInterface $root): void
{
$root->getFullname()->willReturn('Category');
$this->setName('T-shirts');

$root->addChild($this)->shouldBeCalled();
$this->setParent($root);

$this->getFullname()->shouldReturn('Category / T-shirts');
$this->getFullname(' -- ')->shouldReturn('Category -- T-shirts');
}

function it_has_no_description_by_default(): void
{
$this->getDescription()->shouldReturn(null);
Expand Down

0 comments on commit 715ddd8

Please sign in to comment.