php - Sonata-admin cannot modify classes with inheritance -


i using symfony2 , have hierarchy of classes. hierarchy pretty simple, have question (the parent) , many different sub-questions. using sonata, want able create different types of questions, sub-questions. so, created hierarchy of classes follows :

hippy\scavengerhuntbundle\entity\question:     type: entity     table: null     inheritancetype: joined     discriminatorcolumn:         name: subclass         type: string     discriminatormap:         blurredmultiplechoicequestion: blurredmultiplechoicequestion         blurredtextquestion: blurredtextquestion         slidingpuzzlequestion: slidingpuzzlequestion         associationquestion: associationquestion         trueorfalsequestion: trueorfalsequestion         lettersinorderquestion: lettersinorderquestion         shorttextquestion: shorttextquestion         multiplechoicequestion: multiplechoicequestion         sentencegapquestion: sentencegapquestion     fields:         id:             type: integer             id: true             generator:                 strategy: auto         title:             type: string             length: 255         position:             type: integer          lifecyclecallbacks: {  } 

and i'll show 1 example of subclass

hippy\scavengerhuntbundle\entity\lettersinorderquestion:     type: entity     table: null     fields:         description:             type: text       lifecyclecallbacks: {  }  <?php  namespace hippy\scavengerhuntbundle\entity;  use doctrine\orm\mapping orm;  /**  * lettersinorderquestion  */ class lettersinorderquestion extends question {     /**      * @var string      */     private $description;       /**      * set description      *      * @param string $description      * @return lettersinorderquestion      */     public function setdescription($description)     {         $this->description = $description;          return $this;     }      /**      * description      *      * @return string       */     public function getdescription()     {         return $this->description;     }   } 

at point, seems set (the database , php classes).

now, want integrate sonataadmin, added following in services

sonata.admin.question:     class: hippy\scavengerhuntbundle\admin\questionadmin     tags:         - { name: sonata.admin, manager_type: orm, group: "questions", label: "question" }     arguments:         - ~         - hippy\scavengerhuntbundle\entity\question         - ~     calls:         - [ settranslationdomain, [hippyscavengerhuntbundle]]         - [ setsubclasses, [{lettersinorderquestion : "hippy\scavengerhuntbundle\entity\lettersinorderquestion"}]] 

and created class questionadmin.php

<?php // src/acme/demobundle/admin/postadmin.php  namespace hippy\scavengerhuntbundle\admin;   use sonata\adminbundle\admin\admin; use sonata\adminbundle\datagrid\listmapper; use sonata\adminbundle\datagrid\datagridmapper; use sonata\adminbundle\form\formmapper;  use hippy\scavengerhuntbundle\entity\lettersinoderquestion;   class questionadmin extends admin {     // fields shown on create/edit forms     protected function configureformfields(formmapper $formmapper)     {          $subject = $this->getsubject();          var_dump($subject);         //exit();           if ($subject instanceof lettersinorderquestionadmin) {             $formmapper->add('description', 'text');         }        }        // fields shown on filter forms     protected function configuredatagridfilters(datagridmapper $datagridmapper)     {         $datagridmapper             ->add('title')          ;     }      // fields shown on lists     protected function configurelistfields(listmapper $listmapper)     {         $listmapper             ->addidentifier('title')         ;     } } 

at point, 1 thing cool sonata admin seems recognize i'm dealing subclasses, take : enter image description here

my problem when try create lettersinorderquestion object, not recognized lettersinorderquestion question. see here : enter image description here

we can see, first via var_dump , second because form description not show, object passed question , not lettersinorderquestion, though url

/admin/hippy/scavengerhunt/question/create?subclass=lettersinorderquestion 

i'm running out of ideas....

edit1:

in question adminclass, in configureformfields method, added

var_dump($this->getsubclasses()); 

and result following:

array (size=1)  'lettersinorderquestion' => string 'hippy\scavengerhuntbundle\entity
ettersinorderquestion' (length=56) 

therefore, looks there error in parsing of entity class name gets mixed up...

first, there typo in namespace in questionadmin, should be

use hippy\scavengerhuntbundle\entity\lettersinorderquestion;

and not (oder instead of order"

use hippy\scavengerhuntbundle\entity\lettersinoderquestion;

secondly, in questionadmin, mixing admin class , entity class. see here, have:

if ($subject instanceof lettersinorderquestionadmin) { 

it should be, according code:

if ($subject instanceof lettersinorderquestion) {

finally, in sonataadmin, looks if put 1 subclass, class never gets active. have put @ least 2 subclasses, if not, subclass never gets active, see here :

public function hasactivesubclass() {     if (count($this->subclasses) > 1 && $this->request) {         return null !== $this->getrequest()->query->get('subclass');     }      return false; }  

an issue has been opened here : https://github.com/sonata-project/sonataadminbundle/issues/1945


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -