Skip to content

Commit efa0b44

Browse files
Merge pull request #1 from tetranz/master
Update master
2 parents f75fd13 + dda18dc commit efa0b44

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ Because the handling of requests is usually very similar you can use a service w
326326

327327
### Templating
328328

329-
If you need [Templating](https://select2.github.io/examples.html#templating) in Select2, you could consider the following example that shows the country flag next to each option.
329+
If you need [Templating](https://select2.org/dropdown#templating) in Select2, you could consider the following example that shows the country flag next to each option.
330330

331331
Your custom transformer should return data like this:
332332
```javascript

Resources/config/services.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<argument>%tetranz_select2_entity.config%</argument>
1313
</service>
1414
<service id="tetranz_select2entity.autocomplete_service" class="Tetranz\Select2EntityBundle\Service\AutocompleteService">
15-
<argument type="service" id="service_container" />
15+
<argument type="service" id="form.factory" />
16+
<argument type="service" id="doctrine" />
1617
</service>
1718
</services>
1819

Service/AutocompleteService.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,34 @@
22

33
namespace Tetranz\Select2EntityBundle\Service;
44

5+
use Doctrine\Common\Persistence\ManagerRegistry;
56
use Doctrine\ORM\EntityRepository;
6-
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
7-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
8-
use Symfony\Component\DependencyInjection\ContainerInterface;
7+
use Symfony\Component\Form\FormFactoryInterface;
98
use Symfony\Component\Form\FormTypeInterface;
109
use Symfony\Component\HttpFoundation\Request;
1110
use Symfony\Component\PropertyAccess\PropertyAccess;
1211

13-
class AutocompleteService implements ContainerAwareInterface
12+
class AutocompleteService
1413
{
15-
use ContainerAwareTrait;
14+
/**
15+
* @var FormFactoryInterface
16+
*/
17+
private $formFactory;
1618

19+
/**
20+
* @var ManagerRegistry
21+
*/
22+
private $doctrine;
1723

18-
public function __construct(ContainerInterface $container)
24+
/**
25+
* @param FormFactoryInterface $formFactory
26+
* @param ManagerRegistry $doctrine
27+
*/
28+
public function __construct(FormFactoryInterface $formFactory, ManagerRegistry $doctrine)
1929
{
20-
$this->setContainer($container);
21-
}
30+
$this->formFactory = $formFactory;
31+
$this->doctrine = $doctrine;
32+
}
2233

2334
/**
2435
* @param Request $request
@@ -28,11 +39,11 @@ public function __construct(ContainerInterface $container)
2839
*/
2940
public function getAutocompleteResults(Request $request, $type)
3041
{
31-
$form = $this->container->get('form.factory')->create($type);
42+
$form = $this->formFactory->create($type);
3243
$fieldOptions = $form->get($request->get('field_name'))->getConfig()->getOptions();
3344

3445
/** @var EntityRepository $repo */
35-
$repo = $this->container->get('doctrine')->getRepository($fieldOptions['class']);
46+
$repo = $this->doctrine->getRepository($fieldOptions['class']);
3647

3748
$term = $request->get('q');
3849

@@ -54,8 +65,7 @@ public function getAutocompleteResults(Request $request, $type)
5465
->setFirstResult($offset)
5566
;
5667

57-
58-
if (array_key_exists('callback', $fieldOptions)) {
68+
if (is_callable($fieldOptions['callback'])) {
5969
$cb = $fieldOptions['callback'];
6070

6171
$cb($countQB, $request);
@@ -75,4 +85,4 @@ public function getAutocompleteResults(Request $request, $type)
7585

7686
return $result;
7787
}
78-
}
88+
}

0 commit comments

Comments
 (0)