mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #1724 from open-sausages/pulls/4.0/i18n-symfony
Upgrade cms for new i18n backend
This commit is contained in:
commit
554bbc90a2
@ -597,8 +597,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
$result = new ArrayList();
|
||||
|
||||
foreach($classes as $class) {
|
||||
$instance = singleton($class);
|
||||
|
||||
$instance = SiteTree::singleton($class);
|
||||
if($instance instanceof HiddenClass) {
|
||||
continue;
|
||||
}
|
||||
@ -608,27 +607,16 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
continue;
|
||||
}
|
||||
|
||||
$addAction = $instance->i18n_singular_name();
|
||||
|
||||
// Get description (convert 'Page' to 'SiteTree' for correct localization lookups)
|
||||
$i18nClass = ($class == 'Page') ? 'SilverStripe\\CMS\\Model\\SiteTree' : $class;
|
||||
$description = _t($i18nClass . '.DESCRIPTION');
|
||||
|
||||
if(!$description) {
|
||||
$description = $instance->uninherited('description');
|
||||
}
|
||||
|
||||
if($class == 'Page' && !$description) {
|
||||
$description = SiteTree::singleton()->uninherited('description');
|
||||
}
|
||||
$singularName = $instance->i18n_singular_name();
|
||||
$description = $instance->i18n_description();
|
||||
|
||||
$result->push(new ArrayData(array(
|
||||
'ClassName' => $class,
|
||||
'AddAction' => $addAction,
|
||||
'AddAction' => $singularName,
|
||||
'Description' => $description,
|
||||
// TODO Sprite support
|
||||
'IconURL' => $instance->stat('icon'),
|
||||
'Title' => singleton($class)->i18n_singular_name(),
|
||||
'Title' => $singularName,
|
||||
)));
|
||||
}
|
||||
|
||||
@ -931,7 +919,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
// Don't allow navigating into children nodes on filtered lists
|
||||
$fields = array(
|
||||
'getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'),
|
||||
'singular_name' => _t('SiteTree.PAGETYPE'),
|
||||
'singular_name' => _t('SiteTree.PAGETYPE', 'Page Type'),
|
||||
'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated'),
|
||||
);
|
||||
/** @var GridFieldSortableHeader $sortableHeader */
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace SilverStripe\CMS\Controllers;
|
||||
|
||||
use Page;
|
||||
use SilverStripe\Admin\AddToCampaignHandler;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
@ -86,14 +88,14 @@ class CMSPageEditController extends CMSMain {
|
||||
public function getAddToCampaignForm($id)
|
||||
{
|
||||
// Get record-specific fields
|
||||
$record = \Page::get()->byID($id);
|
||||
$record = SiteTree::get()->byID($id);
|
||||
|
||||
if (!$record) {
|
||||
$this->httpError(404, _t(
|
||||
'AssetAdmin.ErrorNotFound',
|
||||
'That {Type} couldn\'t be found',
|
||||
'',
|
||||
['Type' => _t('SiteTree.SINGULARNAME')]
|
||||
['Type' => Page::singleton()->i18n_singular_name()]
|
||||
));
|
||||
return null;
|
||||
}
|
||||
@ -102,7 +104,7 @@ class CMSPageEditController extends CMSMain {
|
||||
'AssetAdmin.ErrorItemPermissionDenied',
|
||||
'It seems you don\'t have the necessary permissions to add {ObjectTitle} to a campaign',
|
||||
'',
|
||||
['ObjectTitle' => _t('SiteTree.SINGULARNAME')]
|
||||
['ObjectTitle' => Page::singleton()->i18n_singular_name()]
|
||||
));
|
||||
return null;
|
||||
}
|
||||
|
@ -447,7 +447,7 @@ class CMSPageHistoryController extends CMSMain {
|
||||
|
||||
public function Breadcrumbs($unlinked = false) {
|
||||
$crumbs = parent::Breadcrumbs($unlinked);
|
||||
$crumbs[0]->Title = _t('CMSPagesController.MENUTITLE');
|
||||
$crumbs[0]->Title = _t('CMSPagesController.MENUTITLE', 'Pages');
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ class CMSPageSettingsController extends CMSMain {
|
||||
|
||||
public function Breadcrumbs($unlinked = false) {
|
||||
$crumbs = parent::Breadcrumbs($unlinked);
|
||||
$crumbs[0]->Title = _t('CMSPagesController.MENUTITLE');
|
||||
$crumbs[0]->Title = _t('CMSPagesController.MENUTITLE', 'Pages');
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
|
@ -355,7 +355,7 @@ HTML;
|
||||
$dateObj = DBField::create_field('Datetime', $date);
|
||||
// $dateObj->setVal($date);
|
||||
return "<div id=\"SilverStripeNavigatorMessage\">" .
|
||||
_t('ContentController.ARCHIVEDSITEFROM') .
|
||||
_t('ContentController.ARCHIVEDSITEFROM', 'Archived site from') .
|
||||
"<br>" . $dateObj->Nice() . "</div>";
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,10 @@ use SilverStripe\CMS\Controllers\ContentController;
|
||||
use SilverStripe\CMS\Controllers\ModelAsController;
|
||||
use SilverStripe\CMS\Controllers\RootURLController;
|
||||
use SilverStripe\CMS\Forms\SiteTreeURLSegmentField;
|
||||
use SilverStripe\Control\ContentNegotiator;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Control\RequestHandler;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Convert;
|
||||
@ -106,7 +108,9 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
* @config
|
||||
* @var array
|
||||
*/
|
||||
private static $allowed_children = array("SilverStripe\\CMS\\Model\\SiteTree");
|
||||
private static $allowed_children = [
|
||||
self::class
|
||||
];
|
||||
|
||||
/**
|
||||
* The default child class for this page.
|
||||
@ -185,8 +189,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
);
|
||||
|
||||
private static $many_many = array(
|
||||
"ViewerGroups" => "SilverStripe\\Security\\Group",
|
||||
"EditorGroups" => "SilverStripe\\Security\\Group",
|
||||
"ViewerGroups" => Group::class,
|
||||
"EditorGroups" => Group::class,
|
||||
);
|
||||
|
||||
private static $has_many = array(
|
||||
@ -241,18 +245,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
*/
|
||||
private static $icon = null;
|
||||
|
||||
/**
|
||||
* @config
|
||||
* @var string Description of the class functionality, typically shown to a user
|
||||
* when selecting which page type to create. Translated through {@link provideI18nEntities()}.
|
||||
*/
|
||||
private static $description = 'Generic content page';
|
||||
|
||||
private static $extensions = array(
|
||||
'SilverStripe\\ORM\\Hierarchy\\Hierarchy',
|
||||
'SilverStripe\\ORM\\Versioning\\Versioned',
|
||||
"SilverStripe\\CMS\\Model\\SiteTreeLinkTracking"
|
||||
);
|
||||
private static $extensions = [
|
||||
Hierarchy::class,
|
||||
Versioned::class,
|
||||
SiteTreeLinkTracking::class,
|
||||
];
|
||||
|
||||
private static $searchable_fields = array(
|
||||
'Title',
|
||||
@ -302,6 +299,46 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
|
||||
protected $_cache_statusFlags = null;
|
||||
|
||||
/**
|
||||
* Plural form for SiteTree / Page classes. Not inherited by subclasses.
|
||||
*
|
||||
* @config
|
||||
* @var string
|
||||
*/
|
||||
private static $base_plural_name = 'Pages';
|
||||
|
||||
/**
|
||||
* Plural form for SiteTree / Page classes. Not inherited by subclasses.
|
||||
*
|
||||
* @config
|
||||
* @var string
|
||||
*/
|
||||
private static $base_singular_name = 'Page';
|
||||
|
||||
/**
|
||||
* Description of the class functionality, typically shown to a user
|
||||
* when selecting which page type to create. Translated through {@link provideI18nEntities()}.
|
||||
*
|
||||
* @see SiteTree::description()
|
||||
* @see SiteTree::i18n_description()
|
||||
*
|
||||
* @config
|
||||
* @var string
|
||||
*/
|
||||
private static $description = null;
|
||||
|
||||
/**
|
||||
* Description for Page and SiteTree classes, but not inherited by subclasses.
|
||||
* override SiteTree::$description in subclasses instead.
|
||||
*
|
||||
* @see SiteTree::description()
|
||||
* @see SiteTree::i18n_description()
|
||||
*
|
||||
* @config
|
||||
* @var string
|
||||
*/
|
||||
private static $base_description = 'Generic content page';
|
||||
|
||||
/**
|
||||
* Fetches the {@link SiteTree} object that maps to a link.
|
||||
*
|
||||
@ -315,7 +352,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
* @param bool $cache True (default) to use caching, false to force a fresh search from the database
|
||||
* @return SiteTree
|
||||
*/
|
||||
static public function get_by_link($link, $cache = true) {
|
||||
public static function get_by_link($link, $cache = true) {
|
||||
if(trim($link, '/')) {
|
||||
$link = trim(Director::makeRelative($link), '/');
|
||||
} else {
|
||||
@ -819,7 +856,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
*/
|
||||
public function getParent() {
|
||||
if ($parentID = $this->getField("ParentID")) {
|
||||
return DataObject::get_by_id("SilverStripe\\CMS\\Model\\SiteTree", $parentID);
|
||||
return DataObject::get_by_id(self::class, $parentID);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -1459,7 +1496,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
));
|
||||
}
|
||||
|
||||
$charset = Config::inst()->get('SilverStripe\\Control\\ContentNegotiator', 'encoding');
|
||||
$charset = ContentNegotiator::config()->get('encoding');
|
||||
$tags[] = FormField::create_tag('meta', array(
|
||||
'http-equiv' => 'Content-Type',
|
||||
'content' => 'text/html; charset=' . $charset,
|
||||
@ -1573,6 +1610,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
// If there is no URLSegment set, generate one from Title
|
||||
$defaultSegment = $this->generateURLSegment(_t(
|
||||
'CMSMain.NEWPAGE',
|
||||
'New {pagetype}',
|
||||
array('pagetype' => $this->i18n_singular_name())
|
||||
));
|
||||
if((!$this->URLSegment || $this->URLSegment == $defaultSegment) && $this->Title) {
|
||||
@ -1707,7 +1745,9 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
}
|
||||
|
||||
if(!self::config()->nested_urls || !$this->ParentID) {
|
||||
if(class_exists($this->URLSegment) && is_subclass_of($this->URLSegment, 'SilverStripe\\Control\\RequestHandler')) return false;
|
||||
if(class_exists($this->URLSegment) && is_subclass_of($this->URLSegment, RequestHandler::class)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Filters by url, id, and parent
|
||||
@ -1959,6 +1999,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
->setURLPrefix($baseLink)
|
||||
->setDefaultURL($this->generateURLSegment(_t(
|
||||
'CMSMain.NEWPAGE',
|
||||
'New {pagetype}',
|
||||
array('pagetype' => $this->i18n_singular_name())
|
||||
)));
|
||||
$helpText = (self::config()->nested_urls && $this->Children()->count())
|
||||
@ -2844,18 +2885,55 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the translated Singular name.
|
||||
* Default singular name for page / sitetree
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function i18n_singular_name() {
|
||||
// Convert 'Page' to 'SiteTree' for correct localization lookups
|
||||
/** @skipUpgrade */
|
||||
// @todo When we namespace translations, change 'SiteTree' to FQN of the class
|
||||
$class = (static::class == 'Page' || static::class === self::class)
|
||||
? 'SiteTree'
|
||||
: static::class;
|
||||
return _t($class.'.SINGULARNAME', $this->singular_name());
|
||||
public function singular_name() {
|
||||
$base = in_array(static::class, [Page::class, self::class]);
|
||||
if ($base) {
|
||||
return $this->stat('base_singular_name');
|
||||
}
|
||||
return parent::singular_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default plural name for page / sitetree
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function plural_name() {
|
||||
$base = in_array(static::class, [Page::class, self::class]);
|
||||
if ($base) {
|
||||
return $this->stat('base_plural_name');
|
||||
}
|
||||
return parent::plural_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description for this page
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function description() {
|
||||
$base = in_array(static::class, [Page::class, self::class]);
|
||||
if ($base) {
|
||||
return $this->stat('base_description');
|
||||
}
|
||||
return $this->stat('description');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get localised description for this page
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function i18n_description() {
|
||||
$description = $this->description();
|
||||
if ($description) {
|
||||
return _t(static::class.'.DESCRIPTION', $description);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2867,17 +2945,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
public function provideI18nEntities() {
|
||||
$entities = parent::provideI18nEntities();
|
||||
|
||||
if(isset($entities['Page.SINGULARNAME'])) $entities['Page.SINGULARNAME'][3] = CMS_DIR;
|
||||
if(isset($entities['Page.PLURALNAME'])) $entities['Page.PLURALNAME'][3] = CMS_DIR;
|
||||
|
||||
$entities[static::class . '.DESCRIPTION'] = array(
|
||||
$this->stat('description'),
|
||||
'Description of the page type (shown in the "add page" dialog)'
|
||||
);
|
||||
|
||||
$entities['SiteTree.SINGULARNAME'][0] = 'Page';
|
||||
$entities['SiteTree.PLURALNAME'][0] = 'Pages';
|
||||
|
||||
// Add optional description
|
||||
$description = $this->description();
|
||||
if ($description) {
|
||||
$entities[static::class . '.DESCRIPTION'] = $description;
|
||||
}
|
||||
return $entities;
|
||||
}
|
||||
|
||||
@ -2897,8 +2969,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
self::$cache_permissions = array();
|
||||
}
|
||||
|
||||
static public function on_db_reset() {
|
||||
public static function on_db_reset() {
|
||||
self::$cache_permissions = array();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -314,8 +314,8 @@ de:
|
||||
SINGULARNAME: Weiterleitungsseite
|
||||
SilverStripe\CMS\Model\SiteTree:
|
||||
DESCRIPTION: 'Allgemeine Inhaltsseite'
|
||||
PLURALNAME: Seitenbäume
|
||||
SINGULARNAME: Seitenbaum
|
||||
PLURALNAME: Seiten
|
||||
SINGULARNAME: Seite
|
||||
SilverStripe\CMS\Model\VirtualPage:
|
||||
DESCRIPTION: 'Zeigt den Inhalt einer anderen Seite an'
|
||||
PLURALNAME: 'Virtuelle Seiten'
|
||||
|
16
lang/en.yml
16
lang/en.yml
@ -338,18 +338,30 @@ en:
|
||||
SilverStripe\CMS\Model\ErrorPage:
|
||||
DESCRIPTION: 'Custom content for different error cases (e.g. "Page not found")'
|
||||
PLURALNAME: 'Error Pages'
|
||||
PLURALS:
|
||||
one: 'An Error Page'
|
||||
other: '{count} Error Pages'
|
||||
SINGULARNAME: 'Error Page'
|
||||
SilverStripe\CMS\Model\RedirectorPage:
|
||||
DESCRIPTION: 'Redirects to an internal page or an external URL'
|
||||
PLURALNAME: 'Redirector Pages'
|
||||
PLURALS:
|
||||
one: 'A Redirector Page'
|
||||
other: '{count} Redirector Pages'
|
||||
SINGULARNAME: 'Redirector Page'
|
||||
SilverStripe\CMS\Model\SiteTree:
|
||||
DESCRIPTION: 'Generic content page'
|
||||
PLURALNAME: 'Site Trees'
|
||||
SINGULARNAME: 'Site Tree'
|
||||
PLURALNAME: Pages
|
||||
PLURALS:
|
||||
one: 'A Page'
|
||||
other: '{count} Pages'
|
||||
SINGULARNAME: Page
|
||||
SilverStripe\CMS\Model\VirtualPage:
|
||||
DESCRIPTION: 'Displays the content of another page'
|
||||
PLURALNAME: 'Virtual Pages'
|
||||
PLURALS:
|
||||
one: 'A Virtual Page'
|
||||
other: '{count} Virtual Pages'
|
||||
SINGULARNAME: 'Virtual Page'
|
||||
SiteConfig:
|
||||
DEFAULTTHEME: '(Use default theme)'
|
||||
|
@ -790,6 +790,7 @@ class SiteTreeTest extends SapphireTest {
|
||||
$sitetree = new SiteTree();
|
||||
$sitetree->Title = _t(
|
||||
'CMSMain.NEWPAGE',
|
||||
'New {pagetype}',
|
||||
array('pagetype' => $sitetree->i18n_singular_name())
|
||||
);
|
||||
$sitetree->write();
|
||||
@ -817,10 +818,13 @@ class SiteTreeTest extends SapphireTest {
|
||||
$sitetree = new SiteTree();
|
||||
$sitetree->Title = _t(
|
||||
'CMSMain.NEWPAGE',
|
||||
'New {pagetype}',
|
||||
array('pagetype' => $sitetree->i18n_singular_name())
|
||||
);
|
||||
$sitetree->write();
|
||||
$this->assertEquals($sitetree->URLSegment, 'neue-seite',
|
||||
$this->assertEquals(
|
||||
'neue-seite',
|
||||
$sitetree->URLSegment,
|
||||
'Sets based on default title on first save'
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user