SilverStripe Fluent - 未创建DataObject Live版本

时间:2018-03-29 14:56:16

标签: php silverstripe silverstripe-4

仅在SS 4.0.3上对于DataObjects(具有多个关系),在CMS端保存期间不会创建DB Localised_Live表版本。这会在前端页面上生成NULL内容。

如果我以管理员身份登录并在草稿模式中检查其中一个页面(实际上与3个不同的 DataObjects 相同),我会定期看到内容。

以下是几个屏幕截图:

Front end

Database

这里涉及的代码(只挑选3个中的1个 - 是相同的):

数据对象

<?php
// Definizione Namespace
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Image;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\TextField;
use SilverStripe\AssetAdmin\Forms\UploadField;

/**
 * Classe Headline
 */
class Headline extends DataObject {
    // Dichiarazione Proprietà
    private static $db = [
        'Corpo' => 'HTMLText'
    ];
    private static $has_one = [
        'LogoHeadline' => Image::class,
        'Home' => 'Home'
    ];
    private static $searchable_fields = [
        'Corpo'
    ];
    private static $summary_fields = [
        'Corpo'
    ];
    private static $translate = [
        'Corpo'
    ];

    /**
     * Metogo definizione campi obbligatori
     * Setter
     * @return void
     */
    public function getCMSValidator() {
        return new RequiredFields(array('LogoHeadline'));
    }

    /**
     * Metodo gestione campi CMS
     * Setter
     * @return FieldList $fields Campi Back-End
     */
    public function getCMSfields()
    {
        $cartellaHome = 'home';
        $dimensioneFoto = 0.6 * 1024 * 1024; // 600 Kb
        $uploadFoto = new UploadField('LogoHeadline', 'Carosello (.jpg/.jpeg/.png/.gif - 600 Kb max.)');

        $uploadFoto->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
        $uploadFoto->getValidator()->setAllowedMaxFileSize($dimensioneFoto);

        Folder::find_or_make($cartellaHome);

        $uploadFoto->setFolderName($cartellaHome);

        $fields = FieldList::create(
            $uploadFoto,
            TextField::create('Corpo', 'Testo')
        );

        $this->extend('updateCMSFields', $fields);

        return $fields;
    }
}

页:

<?php
// Definizione Namespace
use SilverStripe\Forms\FieldList;
use SilverStripe\Assets\Folder;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Assets\Image;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\AssetAdmin\Forms\UploadField;

/**
 * Classe Home
 */
class Home extends Page
{
    // Dichiarazione Proprietà
    private static $db = [
        'Summary' => 'HTMLText',
        'LinkCta' => 'Text'
    ];
    private static $has_many = [
        'Headlines' => 'Headline'
    ];
    private static $many_many = [
        'Cliente' => Image::class
    ];
    private static $translate = [
        'Summary',
        'LinkCta',
        'Headlines'
    ];
    private static $description = 'Home Page';

    /**
     * Metodo gestione campi Back-End
     * Getter
     * @return FieldList $fields Campi Back-End
     */
    public function getCMSFields()
    {
        $fields = Page::getCMSFields();

        $cartellaClienti = 'clienti';
        $dimensioneFoto = 0.6 * 1024 * 1024; // 600 Kb

        $fields->removeFieldFromTab('Root.Main', 'Content');
        $fields->addFieldToTab('Root.Main', TextareaField::create('Summary', 'Riepilogo'));
        $fields->addFieldToTab('Root.Main', TextField::create('LinkCta', 'Link (Call to Action)'));

        $headlineConfig = GridFieldConfig_RecordEditor::create();

        $fields->addFieldToTab('Root.Headline', new GridField('Headlines', 'Headline', $this->Headlines(), $headlineConfig));
        $fields->addFieldToTab('Root.Clienti', $uploadClienti = new UploadField('Cliente', 'Clienti (.jpg/.jpeg/.png/.gif - 600 Kb max.)'));
        $uploadClienti->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
        $uploadClienti->getValidator()->setAllowedMaxFileSize($dimensioneFoto);

        Folder::find_or_make($cartellaClienti);

        $uploadClienti->setFolderName($cartellaClienti);

        return $fields;
    }
}

YAML

---
Name: corporate-consulting
---
SilverStripe\Core\Manifest\ModuleManifest:
  project: corporate-consulting
# Localizzazione
SilverStripe\i18n\i18n:
  default_locale: 'it_IT'
  common_locales:
    it_IT:
      name: 'Italian'
      native: 'Italiano'
    en_GB:
      name: 'English'
      native: 'English'
TractorCow\Fluent\Extension\FluentDirectorExtension:
  detect_locale: false
# Admin/Branding
SilverStripe\Admin\LeftAndMain:
  application_name: 'Corporate Consulting'
  application_link: 'https://corporate.it'
  extra_requirements_css:
    - themes/corporate/css/dist/admin.css
# Immagini
SilverStripe\Core\Injector\Injector:
 SilverStripe\Assets\Image_Backend:
   properties:
     Quality: 75
---
  Name: traduzioni
---
Caso:
  extensions:
    - 'TractorCow\Fluent\Extension\FluentExtension'
Headline:
  extensions:
    - 'TractorCow\Fluent\Extension\FluentExtension'
Reference:
  extensions:
    - 'TractorCow\Fluent\Extension\FluentExtension'

我愿意接受任何建议。

1 个答案:

答案 0 :(得分:1)

问题解决了。与所涉及的DataObject相关的缺少$owns SiteTree属性(请参阅doc - file ownership)是导致内容无法发布的原因(特别是文件和图像)。

要详细了解它:DataObject Live version not created