dnadesign / silverstripe-elemental-virtual

Allows Content Blocks to be reused between pages.
BSD 3-Clause "New" or "Revised" License
7 stars 26 forks source link

Adding DataExtension for ElementVirtual breaks DataExtension for Elemental BaseElement #29

Closed muppsy007 closed 1 year ago

muppsy007 commented 5 years ago

We have both Elemental and ElementalVirtual installed. Both work fine. But our real elements have some common custom fields that we have introduced via a DataExtension called CustomBaseElement. An example is "Layout" which is used in the template for styling. These are referenced on the template ElementHolder.ss. (something that complicates this issue is ElementalVirtual is not picking up the overrided template, but I see an open issue for that)

With ElementVirtual, it needs to access these same fields via the $this->owner object obviously. So we created another DataExtension to do this:

<?php

use SilverStripe\ORM\DataExtension;

class CustomElementVirtualLinked extends DataExtension
{

  // Add all extra fields added on CustomBaseElement
  public function getLayout()
  {
    return $this->owner->LinkedElement()->Layout;
  }

}

Here is extension.yml:

DNADesign\Elemental\Models\BaseElement:
  extensions:
    - CustomBaseElement
DNADesign\ElementalVirtual\Model\ElementVirtual:
  extensions:
    - CustomVirtualElement

Again, this works. But only if the page has NO proper elements on it. Once a proper element is added to the page, we get an error from that real element. In this example, ElementGallery.

[Emergency] Uncaught BadMethodCallException: Object->__call(): the method 'getLayout' does not exist on 'ElementGallery'

Remove the extension for ElementalVirtual, and everything is fine bar virtual elements are missing out on these methods again.

Why would adding an extension to ElementalVirtual pollute Elemental in such a way?