Just implemented it as an extension on BaseElement for now, works fine for what I need in sorting

and when you publish one page, it updates sort order on all pages

I'm not hugely familier with ss4 owns or many_many but i would think that all the "extraFields" objects that have the sort value need to be owned by the parent object (saving the parent object and all the extrafields objects should be atomic)

  1. public function onAfterPublish()
  2. {
  3. // Force live sort order to match stage sort order
  4. DB::prepared_query(
  5. 'UPDATE "SiteTree_Live"
  6. SET "Sort" = (SELECT "SiteTree"."Sort" FROM "SiteTree" WHERE "SiteTree_Live"."ID" = "SiteTree"."ID")
  7. WHERE EXISTS (SELECT "SiteTree"."Sort" FROM "SiteTree" WHERE "SiteTree_Live"."ID" = "SiteTree"."ID") AND "ParentID" = ?',
  8. array($this->ParentID)
  9. );
  10. }

From SiteTree.php

Yep, I’m probably going to implement that hack for now. When publishing a element, update the sort of all sibling elements to the same values as stage as I need it to work for now. It looks like that is what SiteTree is doing atm

yea, that would be why you'd want the sort order to be part of the "parent" object. I'd want to do the same thing with the way SiteTree works, that would likely be a version bump, but i imagine it wouldn't be too different to having a one-off object like SiteConfig.

The only other way i can think of is bypassing the versioning system when reordering pages and writing directly to the live tables (in addition to the others) when reordering to keep them from getting 'corrupt' but i'd call that a hack