Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/andybaughman/babel into a…

…ndybaughman-master
  • Loading branch information...
commit a6eaeb294628b4dd4ebbb276de6711bda17399e6 2 parents d6c2ee2 + e67f3af
mikrobi authored
Showing with 40 additions and 25 deletions.
  1. +40 −25 core/components/babel/elements/snippets/babellinks.snippet.php
View
65 core/components/babel/elements/snippets/babellinks.snippet.php
@@ -34,6 +34,9 @@
* @param tpl optional: Chunk to display a language link. Default: babelLink
* @param activeCls optional: CSS class name for the current active language. Default: active
* @param showUnpublished optional: flag whether to show unpublished translations. Default: 0
+ * @param showUntranslated optional: flag whether to show links to homepage of inactive language(s) if current page is not translated in that language. Default: 1 //***mod
+ * @param showCurrent optional: include current page in outputted links. Default: 1 //***mod
+ * @param urlScheme optional: flag whether to show unpublished translations. Default: full //***mod
*/
$babel = $modx->getService('babel','Babel',$modx->getOption('babel.core_path',null,$modx->getOption('core_path').'components/babel/').'model/babel/',$scriptProperties);
@@ -50,6 +53,9 @@
$tpl = $modx->getOption('tpl',$scriptProperties,'babelLink');
$activeCls = $modx->getOption('activeCls',$scriptProperties,'active');
$showUnpublished = $modx->getOption('showUnpublished',$scriptProperties,0);
+$showUntranslated = $modx->getOption('showUntranslated',$scriptProperties,0);//***mod
+$showCurrent = $modx->getOption('showCurrent',$scriptProperties,1);//***mod
+$urlScheme = $modx->getOption('urlScheme',$scriptProperties,'full');//***mod
if($resourceId == $modx->resource->get('id')) {
$contextKeys = $babel->getGroupContextKeys($modx->resource->get('context_key'));
@@ -65,32 +71,41 @@
$output = '';
foreach($contextKeys as $contextKey) {
- $context = $modx->getObject('modContext', array('key' => $contextKey));
- if(!$context) {
- $modx->log(modX::LOG_LEVEL_ERROR, 'Could not load context: '.$contextKey);
- continue;
- }
- $context->prepare();
- $cultureKey = $context->getOption('cultureKey',$modx->getOption('cultureKey'));
- $translationAvailable = false;
- if(isset($linkedResources[$contextKey])) {
- $resource = $modx->getObject('modResource',$linkedResources[$contextKey]);
- if($resource && ($showUnpublished || $resource->get('published') == 1)) {
- $translationAvailable = true;
+ $continue = true;//***mod
+ if(!$showCurrent && $contextKey !== $modx->resource->get('context_key')) {//***mod - Check to see if user has chosen not to show current page and if this is the current context page
+ $continue = false;//***mod
+ }//***mod
+ if($continue) { //***mod - Option to only include links to other translated pages. I may not need to include a link to the page I am currently on.
+ $context = $modx->getObject('modContext', array('key' => $contextKey));
+ if(!$context) {
+ $modx->log(modX::LOG_LEVEL_ERROR, 'Could not load context: '.$contextKey);
+ continue;
}
- }
- if($translationAvailable) {
- $url = $context->makeUrl($linkedResources[$contextKey],'','full');
- } else {
- $url = $context->getOption('site_url', $modx->getOption('site_url'));
- }
- $active = ($modx->resource->get('context_key') == $contextKey) ? $activeCls : '';
- $placeholders = array(
- 'cultureKey' => $cultureKey,
- 'url' => $url,
- 'active' => $active,
- 'id' => $translationAvailable? $linkedResources[$contextKey] : '');
- $output .= $babel->getChunk($tpl,$placeholders);
+ $context->prepare();
+ $cultureKey = $context->getOption('cultureKey',$modx->getOption('cultureKey'));
+ $translationAvailable = false;
+ if(isset($linkedResources[$contextKey])) {
+ $resource = $modx->getObject('modResource',$linkedResources[$contextKey]);
+ if($resource && ($showUnpublished || $resource->get('published') == 1)) {
+ $translationAvailable = true;
+ }
+ }
+ if($translationAvailable || $showUntranslated) {//***mod - Give user the option to display/not display link to homepage if translation is not available
+ if($translationAvailable) {//***mod
+ $url = $context->makeUrl($linkedResources[$contextKey],'',$urlScheme);//***mod - Give user more control over generated links url scheme
+ } else {//***mod - Give user the option to display/not display link to alternate homepage if translation is not available
+ $url = $context->getOption('site_url', $modx->getOption('site_url'));//***mod
+ }//***mod
+
+ $active = ($modx->resource->get('context_key') == $contextKey) ? $activeCls : '';
+ $placeholders = array(
+ 'cultureKey' => $cultureKey,
+ 'url' => $url,
+ 'active' => $active,
+ 'id' => $translationAvailable? $linkedResources[$contextKey] : '');
+ $output .= $babel->getChunk($tpl,$placeholders);
+ }//***mod
+ }//***mod
}
return $output;
Please sign in to comment.
Something went wrong with that request. Please try again.