How to automate the publication of files uploaded to a data object in Silverstripe model admin

In Silverstripe 4, the download file must be published before it is visible to the public side of the site.

If I create $ Page with $ has_one Image :: Class, and then also assign $ owns [] to this image, the downloaded image will be published when this page is published.

However, if I create the following structure of data objects, it will not.

Class Item extends DataObject{
    $has_one[
        'ItemImage'=>Image::Class,
        'Catalog'=>'Catalog'
    ];

    $owns[
        'ItemImage'
    ]
}

Class Catalog extend DataObject{
    $has_many[
        'Items'=>'Item'
    ]
    $owns[
        'Items'
    ]

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

        $fields->addFieldToTab('Root.Items', GridField::create('Items', 'Items', $this->Items(), GridFieldConfig_RecordEditor::create()));

        return $fields;

    }
}

If I create a catalog and create elements with images inside it, and then save it, it will not publish the downloaded images. I have to manually: 1. Select an image 2. Edit the original 3. Publish

There should be an easier way for the user.

+4
source share
2

GitHub .

onAfterWrite, DataObject, YML:

My\Data\Object
  extensions:
    - Versioned
+3

Versioned. SiteTree.

Class Item extends DataObject
{
    private static $has_one = [
        'ItemImage' => Image::Class,
        'Catalog' => 'Catalog'
    ];

    private static $owns = [
        'ItemImage'
    ];

    private static $extensions = [
        Versioned::class . '.versioned'
    ];
}

ModelAdmin, , , "" (, SiteTree).

ModelAdmin, :

private static $versioned_gridfield_extensions = true;

ModelAdmin. , , .

+3

Source: https://habr.com/ru/post/1691864/


All Articles