本文整理汇总了PHP中Translatable::locale_filter_enabled方法的典型用法代码示例。如果您正苦于以下问题:PHP Translatable::locale_filter_enabled方法的具体用法?PHP Translatable::locale_filter_enabled怎么用?PHP Translatable::locale_filter_enabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translatable
的用法示例。
在下文中一共展示了Translatable::locale_filter_enabled方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLocaleFilteringEnabledAndDisabled
function testLocaleFilteringEnabledAndDisabled()
{
$this->assertTrue(Translatable::locale_filter_enabled());
// get our base page to use for testing
$origPage = $this->objFromFixture('Page', 'testpage_en');
$origPage->MenuTitle = 'unique-key-used-in-my-query';
$origPage->write();
$origPage->publish('Stage', 'Live');
// create a translation of it so that we can see if translations are filtered
$translatedPage = $origPage->createTranslation('de_DE');
$translatedPage->MenuTitle = $origPage->MenuTitle;
$translatedPage->write();
$translatedPage->publish('Stage', 'Live');
$where = sprintf("\"MenuTitle\" = '%s'", Convert::raw2sql($origPage->MenuTitle));
// make sure that our query was filtered
$this->assertEquals(1, Page::get()->where($where)->count());
// test no filtering with disabled locale filter
Translatable::disable_locale_filter();
$this->assertEquals(2, Page::get()->where($where)->count());
Translatable::enable_locale_filter();
// make sure that our query was filtered after re-enabling the filter
$this->assertEquals(1, Page::get()->where($where)->count());
// test effectiveness of disabling locale filter with 3.x delayed querying
// see https://github.com/silverstripe/silverstripe-translatable/issues/113
Translatable::disable_locale_filter();
// create the DataList while the locale filter is disabled
$dataList = Page::get()->where($where);
Translatable::enable_locale_filter();
// but don't use it until later - after the filter is re-enabled
$this->assertEquals(2, $dataList->count());
}
示例2: augmentSQL
public function augmentSQL(SQLQuery &$query, DataQuery $dataQuery = null)
{
if ($this->owner->ID && !empty($this->owner->Locale)) {
$locale = $this->owner->Locale;
} else {
$locale = Translatable::get_current_locale();
}
if ($locale && Translatable::locale_filter_enabled()) {
$qry = sprintf('"ContentModule"."Locale" = \'%s\'', Convert::raw2sql($locale));
$query->addWhere($qry);
}
}
示例3: start
/**
* Returns the state of other modules before compatibility mode is started.
*
* @return array
*/
public static function start()
{
$compatibility = array(self::SUBSITES => null, self::TRANSLATABLE => null);
if (ClassInfo::exists("Subsite")) {
$compatibility[self::SUBSITES] = Subsite::$disable_subsite_filter;
Subsite::disable_subsite_filter(true);
}
if (ClassInfo::exists("Translatable")) {
$compatibility[self::TRANSLATABLE] = Translatable::locale_filter_enabled();
Translatable::disable_locale_filter();
}
return $compatibility;
}
示例4: disable_locale_filter
/**
* Disables automatic locale filtering in {@link augmentSQL()}. This can be re-enabled
* using {@link enable_locale_filter()}.
*/
public static function disable_locale_filter()
{
self::$locale_filter_enabled = false;
}
示例5: populateSiteConfigDefaults
/**
* When the SiteConfig object is automatically instantiated, we should ensure that
* 1. All SiteConfig objects belong to the same group
* 2. Defaults are correctly initiated from the base object
* 3. The creation mechanism uses the createTranslation function in order to be consistent
* This function ensures that any already created "vanilla" SiteConfig object is populated
* correctly with translated values.
* This function DOES populate the ID field with the newly created object ID
* @see SiteConfig
*/
protected function populateSiteConfigDefaults()
{
// Work-around for population of defaults during database initialisation.
// When the database is being setup singleton('SiteConfig') is called.
if (!DB::getConn()->hasTable($this->owner->class)) {
return;
}
if (!DB::getConn()->hasField($this->owner->class, 'Locale')) {
return;
}
if (DB::getConn()->isSchemaUpdating()) {
return;
}
// Find the best base translation for SiteConfig
$enabled = Translatable::locale_filter_enabled();
Translatable::disable_locale_filter();
$existingConfig = SiteConfig::get()->filter(array('Locale' => Translatable::default_locale()))->first();
if (!$existingConfig) {
$existingConfig = SiteConfig::get()->first();
}
if ($enabled) {
Translatable::enable_locale_filter();
}
// Stage this SiteConfig and copy into the current object
if ($existingConfig && !$existingConfig->getTranslation(Translatable::get_current_locale()) && $existingConfig->canTranslate(null, Translatable::get_current_locale())) {
// Create an unsaved "staging" translated object using the correct createTranslation mechanism
$stagingConfig = $existingConfig->createTranslation(Translatable::get_current_locale(), false);
$this->owner->update($stagingConfig->toMap());
}
// Maintain single translation group for SiteConfig
if ($existingConfig) {
$this->owner->_TranslationGroupID = $existingConfig->getTranslationGroup();
}
$this->owner->Locale = Translatable::get_current_locale();
}