PHP code example of flxlabs / silverstripe-versionedrelations
1. Go to this page and download the library: Download flxlabs/silverstripe-versionedrelations library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
flxlabs / silverstripe-versionedrelations example snippets
class MyObject extends DataObject {
private static $extensions = array(
'Versioned',
'VersionedRelationsExtension',
);
private static $versioned_many_many = array(
'MMRelations' => 'MyRelatedObjectX',
);
private static $versioned_has_many = array(
'HMRelations' => 'MyRelatedObjectY',
);
private static $versioned_has_one = array(
'HORelation' => 'MyRelatedObjectZ',
);
// optionally add extra fields for many-many relations
private static $many_many_extraFields = array(
'Relations' => array(
'MyExtra' => 'Int',
),
);
}
class MyRelatedObjectX extends DataObject {
private static $extensions = array(
'Versioned',
'VersionedRelationsExtension',
);
private static $versioned_belongs_many_many = array(
'MainClasses' => 'MainClass',
);
/*
* NOTE:
* If you use the betterbuttons module,
* get rid of the versioning buttons like this:
*/
public function getBetterButtonsActions() {
$fieldList = FieldList::create(array(
BetterButton_SaveAndClose::create(),
BetterButton_Save::create(),
));
return $fieldList;
}
}
class MyRelatedObjectY extends DataObject {
private static $extensions = array(
'Versioned',
'VersionedRelationsExtension',
);
private static $versioned_belongs_has_many = array(
'MainClass' => 'MainClass',
);
}
class MyRelatedObjectY extends DataObject {
private static $extensions = array(
'Versioned',
'VersionedRelationsExtension',
);
private static $versioned_belongs_to = array(
'MainClass' => 'MainClass',
);
}
…
$this->getVersionedRelation('Relations');
…