ButterflyRay
ButterflyRay

Reputation: 423

How to publish pages via Model Admin in SilverStripe 4?

I have created the Page, Data Object and Model Admin given below.

Page

class MyPage extends Page {

  private static $db = [];
  private static $singular_name = "My Page";
  private static $plural_name = "My Pages";
  private static $description = 'A page created for testing';
}

Data Object

use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject {

  private static $db = [
    'Test' => 'Int'
  ];
}

Model Admin

<?php

use SilverStripe\Admin\ModelAdmin;

class MyAdmin extends ModelAdmin  {

    private static $managed_models = [
        'MyPage',
        'MyDataObject'
    ];

    private static $url_segment = 'my-pages';
    private static $menu_title = 'My Page Admin';
}

When I create a new "MyDataObject" it creates and publishes the object when I click the save button. But when I create a "MyPage" it is still a draft after clicking the save button. I have to open the page from Pages Tree and hit the Publish button to publish the page.

Upvotes: 0

Views: 414

Answers (2)

ButterflyRay
ButterflyRay

Reputation: 423

You have to change your page's code as shown below. (Just add this line - private static $versioned_gridfield_extensions = true; )

<?php

class MyPage extends Page {

  private static $versioned_gridfield_extensions = true;

  private static $db = [];
  private static $singular_name = "My Page";
  private static $plural_name = "My Pages";
  private static $description = 'A page created for testing';

}

Upvotes: 2

asdfsf
asdfsf

Reputation: 71

Page is versioned by default, data objects are not.

https://docs.silverstripe.org/en/4/developer_guides/model/versioning/

Upvotes: 2

Related Questions