Dealing with Sonata's admin final methods

76 Views Asked by At

currently I have this code on my admin class. Since getSubClasses going to become final, this code must change. But HOW? Docs are lacking.

I tried doing setSubClasses in the constructor, but I also need the user object to calculate the classes, and it is not set yet in the constructor...

Basically how do I go about modifying these final methods because there doesn't seem to be a straightforward replacement.

public function getSubClasses()
{
    $subClasses = parent::getSubClasses();
    // ...some code...

    return $subClasses;
}
1

There are 1 best solutions below

0
Petros Pollakis On

I found a solution, not sure if it's correct... Please reply if you know more about this solution.

I was trying to modify getDataSourceIterator() which on sonata 4 they made this method final.

AbstractAdmin.php on version 3

public function getDataSourceIterator()

AbstractAdmin.php on version 4

final public function getDataSourceIterator(): \Iterator

My class is extending the AbstractAdmin and trying to modify the getDataSourceIterator() but with version 4 is not possible cause of the final.

My example:

abstract class AbstractAppAdmin extends AbstractAdmin

and I changed to this

abstract class AbstractAppAdmin extends AbstractAdmin implements AdminInterface

Basically I implement the AdminInterface AGAIN (because is already implemented from AbstractAdmin) and that gives me the freedom to modify the method.

As I said might be bad idea but solved my issue.