Semicolon
Semicolon

Reputation: 1914

SilverStripe retrieve original class name through DataExtension

How can I retrieve the class name (string) of the original class, within a DataExtension?

class FooExtension extends DataExtension {

    // This returns "FooExtension" (but I need the original-class name, not the extension's)
    private $foo1 = self::class;

    // This returns nothing
    public function Foo2 {
        return $this->owner;
    }

    // This returns "FooExtension", surprisingly
    public function Foo3 {
        return get_class($this->owner);
    }

    // This returns nothing either
    public function Foo4 {
        return $this->owner->class;
    }
}

So eg when applying this extension to Page, I want to return or assign Page (string) somewhere in the extension class.

Upvotes: 2

Views: 431

Answers (1)

elliot
elliot

Reputation: 772

You can get the owner's class by calling $this->owner->ClassName from within your DataExtension.

Upvotes: 6

Related Questions