Skip to content

Commit 523e481

Browse files
authored
Create AjaxSelectExtension.php
1 parent a03cc0d commit 523e481

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/DI/AjaxSelectExtension.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Nepttune (https://www.peldax.com)
5+
*
6+
* Copyright (c) 2019 Václav Pelíšek (info@peldax.com)
7+
*
8+
* This software consists of voluntary contributions made by many individuals
9+
* and is licensed under the MIT license. For more information, see
10+
* <https://www.peldax.com>.
11+
*/
12+
13+
declare(strict_types = 1);
14+
15+
namespace Nepttune\DI;
16+
17+
class AjaxSelectExtension extends \Nette\DI\CompilerExtension
18+
{
19+
/**
20+
* @param \Nette\PhpGenerator\ClassType $class
21+
* @return void
22+
*/
23+
public function afterCompile(\Nette\PhpGenerator\ClassType $class) : void
24+
{
25+
$initialize = $class->getMethod('initialize');
26+
$initialize->addBody(__CLASS__ . '::registerControls();');
27+
}
28+
29+
30+
/**
31+
* @return void
32+
*/
33+
public static function registerControls() : void
34+
{
35+
\Nette\Forms\Container::extensionMethod('addAjaxSelect', function (\Nette\Forms\Container $container, $name, $label, callable $function) {
36+
return $container[$name] = new AjaxSelect($label, $function);
37+
});
38+
39+
\Nette\Forms\Container::extensionMethod('addMultiAjaxSelect', function (\Nette\Forms\Container $container, $name, $label, callable $function) {
40+
return $container[$name] = new AjaxMultiSelect($label, $function);
41+
});
42+
}
43+
}

0 commit comments

Comments
 (0)