Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

[SOLVED] Retrieving page links from DOM simpletreedropdown


Go to End


2 Posts   1825 Views

Avatar
Mrfixer

Community Member, 49 Posts

6 September 2011 at 11:53pm

Edited: 07/09/2011 1:35am

For the life of me i cant get this to work.. what im wanting to do is attach a page link to a "Read More" anchor. The simpletreedropdown shows in DOM Just fine, but i just cant get the link to show from the database. The PageLinkID is in the database and also the ID of the page that i want to link to gets populated into the PageLinkID column

This is what i have in my class file:


<?php 

class ImageResource extends DataObject
{
    static $db = array (
        'Title' => 'Text',
        'Caption' => 'Text'
    );
 
    static $has_one = array (
        'HomePage' => 'HomePage',
        'Attachment' => 'Image', //Needs to be an image
        'PageLink' => 'SiteTree'
    );
 
    public function getCMSFields_forPopup()
    {
        return new FieldSet(
            new TextField('Title'),
            new TextareaField('Caption'),
            new FileIFrameField('Attachment'),
            new SimpleTreeDropdownField( 'PageLinkID', 'Link To Page', 'SiteTree' )  
        );
    }
}

Heres HomePage.php


<?php
/**
 * Defining the HomePage page type
 */

class HomePage extends Page {
   static $db = array(
     'effect' => "Enum('sliceDown,sliceDownLeft,sliceUp,sliceUpLeft,sliceUpDown,sliceUpDownLeft,fold,fade,random','random')",
        'slices' => 'Int(15)',
        'animSpeed' => 'Int(500)',
        'pauseTime' => 'Int(3000)',
        'startSlide' => 'Int()',
        'directionNav'  => "Boolean",
        'directionNavHide' => "Boolean",
        'controlNav' => "Boolean",
        'controlNavThumbs' => "Boolean",
        'keyboardNav' => "Boolean",
        'pauseOnHover' => "Boolean",
        'manualAdvance' => "Boolean",
        'captionOpacity' => 'Decimal(2,1,0.8)'
    );  

   static $has_one = array(
   );
   
   static $has_many = array (
        'Images' => 'ImageResource',
        'Panels' => 'NivoSliderPanel',
    );
    
   // static $allowed_children = array('MainBannersResource');
    
   function getCMSFields() {
       
      $fields = parent::getCMSFields();
      
      $manager = new ImageDataObjectManager(
            $this, // Controller
            'Images', // Source name
            'ImageResource', // Source class
            'Attachment', // File name on DataObject
            array(
                'Title' => 'Title', 
                'Caption' => 'Caption',
            ), // Headings 
            'getCMSFields_forPopup' // Detail fields
            // Filter clause
            // Sort clause
            // Join clause
        );
        $manager->setRelationAutoSetting(false); 
         
        $fields->addFieldToTab("Root.Content.Main",$manager);
      
      if (class_exists('DataObjectManager'))$a='DataObjectManager'; else $a='ComplexTableField'; 
      $fields->addFieldToTab("Root.Content.Panels", new $a($this,'Panels','NivoSliderPanel',array('Thumbnail' => _t('Image.PLURALNAME'),'Title' => _t('SiteTree.METATITLE'),'Tagline' => _t('SiteTree.METADESC')), 'getCMSFields_forPopup'));
      
      $fields->addFieldToTab('Root.SliderSettings', new CompositeField(
               new LiteralField("wrapper","<div style='margin-left: 50px;'>"),
                new HeaderField("settings","Slider Settings"),
                new DropdownField('effect',"Effect", singleton('HomePage')->dbObject('effect')->enumValues()),
                new TextField('slices','Number of slices'),
                new TextField('animSpeed','Animation Speed'),
                new TextField('pauseTime','Display panel time'),
                new CheckboxField('randomStartSlide', 'Random 1st panel?'),
                new CheckboxField('directionNav','Show directional Nav?'),
                new CheckboxField('directionNavHide','Only show on hover?'),
                new CheckboxField('controlNav','1,2,3...'),
                new CheckboxField('controlNavThumbs','Thumbs??'),
                new CheckboxField('keyboardNav','Enable keyboard navigation?'),
                new CheckboxField('pauseOnHover','Stop animation while hovering?'),
                new CheckboxField('manualAdvance','Force manual transitions?'),
                new TextField('captionOpacity','Universal caption opacity 0-1'),
            new LiteralField("wrapper_close","</div>")
        ));
        
      $fields->removeFieldFromTab('Root.Content.Main', 'Content');
      
        
        
        $fields->removeFieldFromTab('Root.Content.Main', 'MainPageContent'); 

   return $fields;
 }
   
}

class HomePage_Controller extends Page_Controller { 
       function init(){
    
        parent::init();
        Requirements::css("nivo-slider-silverstripe-extension/css/nivo-slider.css");
        Requirements::javascript("sapphire/thirdparty/jquery/jquery.js");
        
        if (Director::isDev()) {
            Requirements::javascript("nivo-slider-silverstripe-extension/javascript/jquery.nivo.slider.js");
        }else{
            Requirements::javascript("nivo-slider-silverstripe-extension/javascript/jquery.nivo.slider.pack.js");
        }
        
        $a=array();
        
        isset($this->effect) && $this->effect ? $a[]="effect:'{$this->effect}'":null;
        isset($this->slices) && $this->slices ? $a[]="slices:'{$this->slices}'":null;
        isset($this->animSpeed) && $this->animSpeed ? $a[]="animSpeed:'{$this->animSpeed}'":null;
        isset($this->pauseTime) && $this->pauseTime ? $a[]="pauseTime:'{$this->pauseTime}'":null;
        isset($this->startSlide) && $this->startSlide ? $a[]="startSlide:'{$this->startSlide}'":null;
        
        //TODO: Test how clever is a javascript boolean
        isset($this->startSlide) && $this->startSlide ? $a[]="startSlide:true":$a[]="startSlide:false";
        isset($this->directionNav) && $this->directionNav ? $a[]="directionNav:true":$a[]="directionNav:false";
        isset($this->directionNavHide) && $this->directionNavHide ? $a[]="directionNavHide:true":$a[]="directionNavHide:false";
        isset($this->controlNav) && $this->controlNav ? $a[]="controlNav:true":$a[]="controlNav:false";
        isset($this->controlNavThumbs) && $this->controlNavThumbs ? $a[]="controlNavThumbs:true":$a[]="controlNavThumbs:false";
        isset($this->keyboardNav) && $this->keyboardNav ? $a[]="keyboardNav:true":$a[]="keyboardNav:false";
        isset($this->pauseOnHover) && $this->pauseOnHover ? $a[]="pauseOnHover:true":$a[]="pauseOnHover:false";
        isset($this->manualAdvance) && $this->manualAdvance ? $a[]="manualAdvance:true":$a[]="manualAdvance:false";
        
        //isset($this->captionOpacity) && $this->captionOpacity ? $a[]="captionOpacity:'{$this->captionOpacity}'":null;
        
        $a=implode(", ",$a);
        
        Requirements::customScript("
            jQuery(window).load(function($) {
                jQuery('#slider').nivoSlider({{$a}});
            });
        ");
    }
    /**
    public function forTemplate(){

    }
    **/
}

Finally heres the line in HomePage.ss that calls the link:


 <p>$Caption.LimitCharacters(175)<span><a href="$PageLinkID.LINK">Read More</a></span></p>

The line calling the link should have read:


<p>$Caption.LimitCharacters(175)<span><a href="$PageLink.LINK">Read More</a></span></p>

Avatar
MarcelKlomp

Community Member, 5 Posts

7 September 2011 at 7:08pm

Thanks man! Was just working on the some sort of thing and ran into the same problem. Sure I tried it before but forgot to flush -doh-