DeltaCMS/src/AdminPanel/Form/EntityInput.php
Florian Bouillon cacdc2c3d6 Changed whole Input Objects
they now lives by themselves when before
they where highly connected to Form.php
2019-04-25 16:14:25 +02:00

46 lines
1.1 KiB
PHP

<?php
namespace AdminPanel\Form;
use AdminPanel\AdminPanel;
class EntityInput extends AbstractInput
{
public function __construct()
{
$this->setOption("type", "text");
}
public function getOptionsList(): array
{
return array_merge(
parent::getOptionsList(),
array(
'entity'
)
);
}
public function setOption(string $name, $value)
{
if ($name === 'entity') {
$this->options["entities"] = AdminPanel::getInstance()->getEm()->getRepository($value)->findAll();
} elseif ($name === "name") {
$this->attributes["list"] = $value . "_list";
}
parent::setOption($name, $value);
}
public function getOption($name)
{
if ($name === "value") {
$repo = AdminPanel::getInstance()->getEm()->getRepository($this->options["entity"]);
return $repo->findOneBy(array(
'name' => $this->options["value"]
));
} else {
return parent::getOption($name);
}
}
}