We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24374
    • 322 Posts
    Is there any way to add a Parent Resource popup to the articles created by Articles? When using Babel, I can create a translated version just fine, and it displays fine on the front end, but it ends up having a parent ID of 0, and there is no way to change that. I need to make the second language's Articles resource be the parent rather than the first language's Articles resource. Any ideas?
      • 24374
      • 322 Posts
      I created a plugin to post-process the Spanish article to link it to the correct Articles container. It's not very elegant, but it works. I have the pairs IDs embedded in the plugin so it can check which Articles containers should be linked together. I'd still love to hear if any else has experience with this or ideas to share.
        • 36442
        • 97 Posts
        rainbowtiger, would you be so kind to share your solution?
          • 24374
          • 322 Posts
          Pretty simple. Here's the plugin code:

          <?php
          // get the related language ID pairs that Babel puts in
          $context=$resource->get('context_key');
          $langlink=$resource->getTVValue('babelLanguageLinks');
          $langs=explode(';', $langlink);
          
          // if first Babel language key is "web" and we're in the Spanish context,
          // then there is an English version
          if(isset($langs[0]) && substr($langs[0], 0,3)=='web' && $context=='es') {
          	// see what Articles container the English version is in and assign this resource to the Spanish one
          	$res = $modx->getObject('modResource',substr($langs[0],4));
          	$parent= $res->get('parent');
          	if($parent==191) {
          		$res2 = $modx->getObject('modResource',$id);
          		$res2->set('parent',195);
          		$res2->save();
          	}
          
          }
          

          You would add additional blocks of "if($parent==NNN){ . . . }" for however many news sections you have going, setting the parent to the corresponding language's news resource id ("$res2->set('parent',NNN);"), and check off the system event "OnDocFormSave" to trigger the plugin. Set the value of $context in the line ". . . && $context=='es'" to whatever you're using for your second language. I could have gone a step further and had the script discover the ID of the Spanish Articles container, and would do that if I were to make this a publicly available plugin, but my needs were met for this project using just the code above. [ed. note: rainbowtiger last edited this post 14 years, 2 months ago.]
            • 36442
            • 97 Posts
            Thank you so much, rainbowtiger!