FIX Endless loop in Translatable CMS page extension - add temporary inlineformaction
This commit is contained in:
parent
1fffd1b481
commit
836869dfc7
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Translatable\Forms;
|
||||
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\Forms\FormField;
|
||||
use SilverStripe\View\HTML;
|
||||
|
||||
/**
|
||||
* TEMPORARY
|
||||
*
|
||||
* Removed from 4.0 - added temporarily to restore functionality while upgrading to SS4
|
||||
*/
|
||||
class TemporaryInlineFormAction extends FormField
|
||||
{
|
||||
/**
|
||||
* Create a new action button.
|
||||
* @param action The method to call when the button is clicked
|
||||
* @param title The label on the button
|
||||
* @param extraClass A CSS class to apply to the button in addition to 'action'
|
||||
*/
|
||||
public function __construct($action, $title = '', $extraClass = '')
|
||||
{
|
||||
$this->extraClass = ' '.$extraClass;
|
||||
parent::__construct($action, $title);
|
||||
}
|
||||
|
||||
public function performReadonlyTransformation()
|
||||
{
|
||||
return $this->castedCopy('InlineFormAction_ReadOnly');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $properties
|
||||
* @return HTMLText
|
||||
*/
|
||||
public function Field($properties = [])
|
||||
{
|
||||
return DBField::create_field(
|
||||
'HTMLText',
|
||||
HTML::createTag('input', [
|
||||
'type' => 'submit',
|
||||
'name' => sprintf('action_%s', $this->getName()),
|
||||
'value' => $this->title,
|
||||
'id' => $this->ID(),
|
||||
'class' => sprintf('action%s', $this->extraClass),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function Title()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ use SilverStripe\Core\ClassInfo;
|
|||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\HeaderField;
|
||||
use SilverStripe\Forms\HiddenField;
|
||||
use SilverStripe\Forms\InlineFormAction;
|
||||
use SilverStripe\Forms\LiteralField;
|
||||
use SilverStripe\Forms\Tab;
|
||||
use SilverStripe\i18n\i18n;
|
||||
|
@ -35,6 +34,11 @@ use SilverStripe\Translatable\Forms\LanguageDropdownField;
|
|||
use SilverStripe\Translatable\Model\Translatable;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
|
||||
|
||||
|
||||
use SilverStripe\Translatable\Forms\TemporaryInlineFormAction;
|
||||
|
||||
/**
|
||||
* The Translatable decorator allows your DataObjects to have versions in different languages,
|
||||
* defining which fields are can be translated. Translatable can be applied
|
||||
|
@ -1134,12 +1138,11 @@ class Translatable extends DataExtension implements PermissionProvider
|
|||
if ($canAddLocale) {
|
||||
// Only add create button if new languages are available
|
||||
$tab->push(
|
||||
$createButton = InlineFormAction::create(
|
||||
$createButton = TemporaryInlineFormAction::create(
|
||||
'createtranslation',
|
||||
_t('Translatable.CREATEBUTTON', 'Create')
|
||||
)->addExtraClass('createTranslationButton')
|
||||
);
|
||||
$createButton->includeDefaultJS(false); // not fluent API...
|
||||
} else {
|
||||
$tab->removeByName('NewTransLang');
|
||||
$tab->push(new LiteralField(
|
||||
|
@ -1224,7 +1227,7 @@ class Translatable extends DataExtension implements PermissionProvider
|
|||
|
||||
// if a language other than default language is used, we're in "translation mode",
|
||||
// hence have to modify the original fields
|
||||
$baseClass = $this->owner->class;
|
||||
$baseClass = get_class($this->owner);
|
||||
while (($p = get_parent_class($baseClass)) != DataObject::class) {
|
||||
$baseClass = $p;
|
||||
}
|
||||
|
@ -1373,6 +1376,7 @@ class Translatable extends DataExtension implements PermissionProvider
|
|||
if ($this->owner->hasExtension(Versioned::class)) {
|
||||
if ($stage) {
|
||||
Versioned::set_stage($stage);
|
||||
var_dump($stage);
|
||||
}
|
||||
$translations = Versioned::get_by_stage(
|
||||
$baseDataClass,
|
||||
|
@ -1381,6 +1385,7 @@ class Translatable extends DataExtension implements PermissionProvider
|
|||
null
|
||||
)->leftJoin("{$baseDataTable}_translationgroups", $joinOnClause);
|
||||
if ($stage) {
|
||||
var_dump($currentStage);
|
||||
Versioned::set_stage($currentStage);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -508,8 +508,6 @@ class TranslatableTest extends FunctionalTest
|
|||
|
||||
public function testUpdateCMSFieldsOnSiteTree()
|
||||
{
|
||||
$this->markTestSkipped('@todo: This test hangs indefinitely');
|
||||
|
||||
$pageOrigLang = new TranslatableTestPage();
|
||||
$pageOrigLang->write();
|
||||
|
||||
|
@ -1197,8 +1195,6 @@ class TranslatableTest extends FunctionalTest
|
|||
|
||||
public function testSavePageInCMS()
|
||||
{
|
||||
$this->markTestSkipped('@todo: This test hangs indefinitely.');
|
||||
|
||||
$adminUser = $this->objFromFixture(Member::class, 'admin');
|
||||
$enPage = $this->objFromFixture(Page::class, 'testpage_en');
|
||||
|
||||
|
|
Loading…
Reference in New Issue