Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DataObjectManager and Versioned

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 701 Views
  • Myrdhin
    Avatar
    Community Member
    67 Posts

    DataObjectManager and Versioned Link to this post

    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,

  • Myrdhin
    Avatar
    Community Member
    67 Posts

    Re: DataObjectManager and Versioned Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager and Versioned Link to this post

    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

    701 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.