PHP code example of bummzack / translatable-dataobject
1. Go to this page and download the library: Download bummzack/translatable-dataobject library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bummzack / translatable-dataobject example snippets
class TestimonialPage extends Page
{
private static $has_many = array(
'Testimonials' => 'Testimonial'
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
// manage testimonials
$gridConfig = GridFieldConfig_RelationEditor::create();
$gridField = new GridField('Testimonials', 'Testimonials', $this->Master()->Testimonials(), $gridConfig);
$gridField->setModelClass('Testimonial');
$fields->addFieldsToTab('Root.Testimonials', $gridField);
return $fields;
}
}
class TestimonialPage_Controller extends Page_Controller
{
}
public function getCMSFields()
{
$titleField = new TextField('Title');
$contentField = new HtmlEditorField('Content');
// transform the fields if we're not in the default locale
if(Translatable::default_locale() != Translatable::get_current_locale()) {
$transformation = new TranslatableFormFieldTransformation($this);
$titleField = $transformation->transformFormField($titleField);
$contentField = $transformation->transformFormField($contentField);
}
return new FieldList(
$titleField,
$contentField
);
}
public function getCMSFields()
{
// get the current locale
$locale = Translatable::get_current_locale();
return new FieldList(
$this->getLocalizedFormField('Title', $locale),
$this->getLocalizedFormField('Content', $locale)
);
}
public function getCMSFields(){
$fields = new FieldList();
$fields->add($this->getTranslatableTabSet());
return $fields;
}
public function getCMSFields(){
$fields = new FieldList();
$fields->add($this->getTranslatableTabSet());
// add all "Global" fields to another tab
$fields->addFieldsToTab('Root.Global', array(
new TextField('NotTranslatedField'),
new UploadField('MyImage')
// etc...
));
return $fields;
}