Source of file LanguageDataExtension.php
Size: 1,662 Bytes - Last Modified: 2022-02-21T10:01:58+00:00
/var/www/docs.ssmods.com/process/src/code/data_extensions/LanguageDataExtension.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 | <?php /** * Provides SiteTree classes with a language menu. * * Add this extension to a SiteTree instance * by adding this to your _config.php: * * Object::add_extension('Page', 'LanguageDataExtension'); * * @package cleanutilities * @subpackage data_extensions * * @author arillo */ class LanguageDataExtension extends DataExtension { /** * Returns a DataList containing Pages. * The provided links point to their translated pages. * You can use it in templates like this: * * <% loop LanguageChooser %> * $Title, $Current, and any other vars in your page instance * <% end_loop %> * * @return DataList */ public function LanguageChooser() { if (!Controller::curr()) { return; } if ($langs = Translatable::get_allowed_locales()) { $data = ArrayList::create(); foreach ($langs as $key => $code) { if ($code == Translatable::get_current_locale()) { $this->owner->Current = 'current'; $data->push($this->owner); } else { $translation = $this->owner->getTranslation($code); if ($translation) { $data->push($translation); } else { $page = Translatable::get_one_by_locale("SiteTree", $code, "URLSegment LIKE 'home%'"); if ($page) { $data->push($page); } } } } return $data; } return false; } } |