Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

DataObjectManager and Versioned


Reply


3 Posts   785 Views

Avatar
Myrdhin

Community Member, 67 Posts

26 November 2010 at 5:51am

Hello,

I would like to manage versioned dataobjects (named "Product"s in my code) with DataObjectManager and have 2 actions boutons 'Save' and 'Save & publish' (like Sitetree objects in CMS) in popups generated by DataObjectManager.

My Product class code is :

<?php

class Product extends DataObject {
   static $db = array(
      'Name' => 'Text',
      'Description' => 'HTMLText',
   );

   static $has_one = array(
      'Page' => 'Page',
   );

   static $extensions = array(
      "Versioned('Stage', 'Live')"
   );

   function getCMSfields() {
      $fields = new FieldSet(
         new TextField('Name', _t('Product.Name', 'Name')),
         new SimpleHtmlEditorField('Description', _t('Product.Description', 'Description'))
      );

      return $fields;
   }
   

}

?>

And for example, my Page class code where i use DataObjectManager :

<?php
class Page extends SiteTree {

   public static $db = array();

   public static $has_one = array();
   public static $has_many = array( 'Products' => 'Product' );

   function getCMSFields() {
      $fields = parent::getCMSFields();

      $productsTable = new DataObjectManager(
         $this, _t('Product.PLURALNAME', 'Products'), 'Product',
         array(
            "Name" => _t('Product.Name', 'Name'),
            "Description" => _t('Product.Description', 'Description'),
         )
      );
      $productsTable->setAddTitle( _t('Product.SINGULARNAME', 'Product'));

      $fields->addFieldToTab('Root.Content.Products', $productsTable);
      $fields->findOrMakeTab('Root.Content.Products')->setTitle( _t('Product.PLURALNAME', 'Products'));

      return $fields;
   }

}

class Page_Controller extends ContentController {

   public static $allowed_actions = array ( );

   public function init() {
      parent::init();
      Requirements::themedCSS('layout');
      Requirements::themedCSS('typography');
      Requirements::themedCSS('form');
   }
}

How can replace the only 'Save' button that appear in the popup with two buttons and there actions associated ?

Thank for your help,

Avatar
Myrdhin

Community Member, 67 Posts

4 December 2010 at 3:00am

Perhaps my question isn't clear ?.. :'(

Avatar
UncleCheese

Forum Moderator, 4092 Posts

4 December 2010 at 5:06am

Generally, the way this is done is to overload the publish/unpublish functions on your parent page, and have those cascade down to the related objects in the DOM.

See the UserDefinedForm module for an example. When the UDF page is published/unpublished, it cuts new versions of the associated form elements.

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com