Enabling Gedmo/Versioned property for entity fields.

0 votes
asked 2 hours ago in General Questions by platzer.jakob (120 points)

My team works on a Symfony project, in which we use Skipper to add/edit/delete entities. We wanted to implement Gedmo's Loggable on selected entities.
Adding Loggable with Skipper is easy, however it is not possible to add Gedmo\Versioned to the fields that should be logged.
The closest I could get to, was to extend Skipper's Gedmo-extension, so that the attribute could be added to the field and the change would be saved in the project.skipper-file, but during export the attribute would be lost.
Is there a best-practice to do this? Do I need to write an additional script to run after the export? Does anyone have any experiences with that?

Thank you in advance for your help.

1 Answer

0 votes
answered 2 hours ago by ludek.vodicka Skipper developer (140,490 points)

Hi,

Good news — you don't need a post-export script or a custom extension for this. Skipper already supports @Gedmo\Versioned fully (it round-trips on both import and export). It's simply modeled in a different place than you'd expect, which is why your custom attribute was saved into the .skipper file but dropped on export.

The key concept

@Gedmo\Versioned is not configured as an attribute on the field. It's configured on the entity's Loggable extension, as a list of the fields (and relations) that should be tracked. During export, Skipper takes that list and writes @Gedmo\Versioned onto each of those fields automatically.

This is the same pattern used by Timestampable, Blameable and IpTraceable — an entity-level list that produces per-field annotations.

How to set it up (no scripting)

  1. Select the entity and open its Gedmo extension settings — the same place where you added Loggable.
  2. Under Loggable → Fields, add one entry per field you want versioned. Each entry is a reference to an existing field on the entity (you pick the field, it's not free text).
  3. For a versioned relation (e.g. a ManyToOne / owning-side association), add it to the association list in the same Loggable section.
  4. Export as usual.

Result

The entity gets @Gedmo\Loggable, and every field/relation you listed gets @Gedmo\Versioned:

/** * @Gedmo\Loggable */ class Article { /** * @Gedmo\Versioned * @ORM\Column(type="string") */ private $title; }

This works for all Doctrine output formats — PHP annotations, PHP 8 attributes, XML and YAML — and it's read back correctly on re-import, so your round-trip stays intact.

Two things to note

  • Please revert the custom Gedmo-extension change you made. The built-in export only emits Versioned from the Loggable fields list, so a separate custom field attribute will always be lost — that part is expected behavior, not a bug.
  • A field has to exist on the entity to be referenced in the Loggable list (it's a field reference). If you were trying to mark something that isn't part of the Skipper model, add it as a field first, then reference it.

Hope this helps — let us know if anything is unclear and we'll be glad to walk through it.

commented 8 minutes ago by platzer.jakob (120 points)

Thank you very much for the reply!

Works like a charm

commented 8 minutes ago by ludek.vodicka Skipper developer (140,490 points)

Glad to hear that. Feel free to let us know if you have any other question or idea how to improve Skipper

...