Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getValue($object)
 {
     if (!is_object($object)) {
         throw new \InvalidArgumentException('Column "gedmo_tree" must read value from object.');
     }
     $value = parent::getValue($object);
     $objectManager = $this->registry->getManager($this->getOption('em'));
     // Check if tree listener is registred.
     $treeListener = $this->getTreeListener($objectManager);
     // Get Tree strategy.
     $strategy = $this->getClassStrategy($objectManager, $treeListener, get_class($object));
     $this->validateStrategy($object, $strategy);
     $config = $treeListener->getConfiguration($objectManager, get_class($object));
     $doctrineDataIndexer = new DoctrineDataIndexer($this->registry, get_class($object));
     $propertyAccessor = PropertyAccess::createPropertyAccessor();
     $this->viewAttributes = array('id' => $doctrineDataIndexer->getIndex($object), 'root' => isset($config['root']) ? $propertyAccessor->getValue($object, $config['root']) : null, 'left' => isset($config['left']) ? $propertyAccessor->getValue($object, $config['left']) : null, 'right' => isset($config['right']) ? $propertyAccessor->getValue($object, $config['right']) : null, 'level' => isset($config['level']) ? $propertyAccessor->getValue($object, $config['level']) : null, 'children' => $this->getTreeRepository(get_class($object), $objectManager)->childCount($object));
     $parent = isset($config['parent']) ? $propertyAccessor->getValue($object, $config['parent']) : null;
     if (isset($parent)) {
         $this->viewAttributes['parent'] = $doctrineDataIndexer->getIndex($parent);
     }
     return $value;
 }
 public function testGetIndexWithSubclass()
 {
     $class = self::FIXTURES . 'Vehicle';
     $dataIndexer = new DoctrineDataIndexer($this->getManagerRegistry(), $class);
     // Creating subclasses of News
     $car = new Car('foo');
     $bike = new Bike('bar');
     $this->assertSame($dataIndexer->getIndex($car), 'foo');
     $this->assertSame($dataIndexer->getIndex($bike), 'bar');
     $this->assertSame($class, $dataIndexer->getClass());
 }