Open ndoulgeridis opened 10 years ago
Hi @crash21
In the generator-XXXX.yml
file, you have a parameter entity_manager
under the main params
key.
You can define your own entity manager name here.
Hello @sescandell,
No its not working. I have researched it deeper and found on
Guesser/DoctrineORMFieldGuesser.php line 164
'em' => 'default', // TODO: shouldn't this be configurable?
Hello,
Any suggestions how to fix this? If possible give me some guidelines from your point of you as you are more experienced with the Bundle and I will fix it.
Thanks.
A workaround would be to:
admingenerator.fieldguesser.doctrine.class
to use your classclass DoctrineORMFieldGuesser extends BaseDoctrineORMFieldGuesser
{
public function getFormOptions($formType, $dbType, $columnName)
{
$formOptions = parent::getFormOptions($formType, $dbType, $columnName);
if (array_key_exists('em', $formOptions)) {
$formOptions['em'] = $this->doctrine->getManagerForClass($formOptions['class']);
}
return $formOptions;
}
}
Let me know if it works, I'll create the right PR
Hmm not really understood :( First of all which builder to extend? There are many builders.
Well what i did is I added in my parameters.yml admingenerator.fieldguesser.doctrine.class to use my Own Class and then added my own DoctrineORMFieldGuesser
use Admingenerator\GeneratorBundle\Guesser\DoctrineORMFieldGuesser as AdminDoctrineORMFieldGuesser;
class DoctrineORMFieldGuesser extends AdminDoctrineORMFieldGuesser
/**
* @param $formType
* @param $dbType
* @param $columnName
* @return array
*/
public function getFormOptions($formType, $dbType, $columnName)
{
$formOptions = parent::getFormOptions($formType, $dbType, $columnName);
if (array_key_exists('em', $formOptions)) {
$formOptions['em'] = $this->doctrine->getManagerForClass($formOptions['class']);
}
return $formOptions;
}
What i get is the following error:
Notice: Undefined property: DoctrineORMFieldGuesser::$doctrine in DoctrineORMFieldGuesser.php line 27
So $this->doctrine seems not working, trying to figure it out.
Well we can use
$formOptions['em'] = $this->container->get("doctrine")->getManagerForClass($formOptions["class"]);
but $this->container->get("doctrine")->getManagerForClass($formOptions["class"]); returns an EntityManager object not a string with connection name...
Notice: Undefined property: DoctrineORMFieldGuesser::$doctrine in DoctrineORMFieldGuesser.php line 27 So $this->doctrine seems not working, trying to figure it out.
Yes, actually $doctrine
is private...
Here is a workaround... waiting for a real fix in the admingen (bubbling the configuration to form generation).
// in your field guesser custom class:
public function getFormOptions($formType, $dbType, $columnName)
{
$formOptions = parent::getFormOptions($formType, $dbType, $columnName);
if (array_key_exists('em', $formOptions)) {
$formOptions['em'] = $this->getObjectManagerName($formOptions['class']);
}
return $formOptions;
}
protected function getObjectManagerName($className)
{
$doctrine = $this->container->get('doctrine');
$om = $doctrine->getManagerForClass($className);
foreach ($doctrine->getManagerNames() as $omName) {
if ($doctrine->getManager($omName) == $om) {
return $omName;
}
}
throw new \Exception('We should never be there');
}
Of course, this is a workaround. You might consider adding some cache capacities (or create a PR to bubble the generator configuration to the form generation :) )
Let me know if it works
Hey I did some fixes and this seems to be working fine:
public function getFormOptions($formType, $dbType, $columnName)
{
$formOptions = parent::getFormOptions($formType, $dbType, $columnName);
if (array_key_exists('em', $formOptions)) {
$formOptions['em'] = $this->getObjectManagerName($formOptions['class']);
}
return $formOptions;
}
protected function getObjectManagerName($className)
{
$doctrine = $this->container->get('doctrine');
$om = $doctrine->getManagerForClass($className);
foreach ($doctrine->getManagerNames() as $emName=>$seviceName)
{
$instance = $doctrine->getManager($emName);
if ($instance == $om)
{
return $emName;
}
}
throw new \Exception('We should never be there');
}
So next step is what now? Move these changes in actual AdminBuilder and PR?
@crash21
git clone (repository git address) (folder to clone into)
your repository to your computer, eg. git clone git@github.com:crash21/AdmingeneratorGeneratorBundle.git admingenerator
(will create a folder "admingenerator" and clone your repo into it)cd admingenerator
to get into the foldergit checkout -b (branch-name)
to create a new branch, eg. git checkout -b fix-issue-806
git add .
then git commit -m "Your commit message"
to add commitsgit push origin fix-issue-806 -f
to push your branch (-f
is for "force", meaning it will create a new branch if it does not exist)
Hello,
I have multiple entity managers I have a generator which has a field
When i load the page I get this error:
Doctrine ORM Manager named "default" does not exist.
I haven't found a way in new docs to add em or entity manager to generator. How can i change default to the right one?