File modules/cms/generator/filter/LinkToObjectsFilter.class.php
Last commit: Sat Mar 13 22:38:30 2021 +0100 Jan Dankert New filter for using links in text nodes (useful in CSS or script files)
1 <?php 2 3 4 namespace cms\generator\filter; 5 6 7 use cms\model\BaseObject; 8 use util\text\variables\VariableResolver; 9 10 class LinkToObjectsFilter extends AbstractFilter 11 { 12 public function filter($value) 13 { 14 $resolver = new VariableResolver(); 15 16 $resolver->addResolver('link',function($key) { 17 18 $targetId = intval( $key ); 19 20 if ( $targetId ) { 21 22 $from = new BaseObject( $this->context->getObjectId() ); 23 $from->load(); 24 $target = new BaseObject( $targetId ); 25 $target->load(); 26 27 $linkScheme = $this->context->getLinkScheme(); 28 return $linkScheme->linkToObject( $from, $target ); 29 } else { 30 return ''; 31 } 32 }); 33 34 return $resolver->resolveVariables( $value ); 35 } 36 37 }
Downloadmodules/cms/generator/filter/LinkToObjectsFilter.class.php
History Sat, 13 Mar 2021 22:38:30 +0100 Jan Dankert New filter for using links in text nodes (useful in CSS or script files)