Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » [SOLVED] Retrieving page links from DOM simpletreedropdown

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 804 Views
  • Mrfixer
    Avatar
    Community Member
    49 Posts

    [SOLVED] Retrieving page links from DOM simpletreedropdown Link to this post

    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>

  • MarcelKlomp
    Avatar
    Community Member
    5 Posts

    Re: [SOLVED] Retrieving page links from DOM simpletreedropdown Link to this post

    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-

    804 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.