Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Customize LinkForm

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

Page: 1
Go to End
Author Topic: 236 Views
  • hemant.chakka
    Avatar
    Community Member
    1 Post

    Customize LinkForm Link to this post

    I am trying to customize the LinkForm that popup when one clicks the link icon on the Html Editor, following is the code I am using to extend the form :

    function updateLinkForm($form) {            
    $fields=$form->Fields();
    $linkType=$fields->dataFieldByName('LinkType');
    if($linkType!=null) {
    Requirements::javascript('dataobject_lightbox_linker/javascript/HtmlEditorToolbarAdditions.js');
    $source=$linkType->getSource();
             $source['DataObjectLightbox']='Lightbox Linker';
             $source['largeImage']=_t('ImageViewer.LINKLARGEIMAGE', 'An Original Size Image');
             $source['video']='A Youtube Video';
    $linkType->setSource($source);
             $currentPageID;   
             if($this->owner->controller->currentPageID() >= 1){
                $currentPageID = $this->owner->controller->currentPageID();
             } else {
                $currentPageID = 0;   
             }   
             //checking if any ModelBox DataObjects exist for this page and fetching them if they do
             if($dataObjects = DataObject::get('ModelBoxDataObject', 'ParentID=' . $currentPageID)){
                $mdls = array();
                if($dataObjects->count()){
                   $mdls['0'] =    'Choose a Model Box To Link to';
                   foreach ($dataObjects as $dataObject){
                      $mdls[$dataObject->ID] = $dataObject->Name;
                   }
                }else{
                   $mdls['0'] =    'No ModelBox(s) for this page';   
                }
                //modelbox DO are avaiable - setup the dropdown
                $linkerField = new DropdownField(
                   'DataObjectLightbox',
                   'Model Box',
                   $mdls
                );
             } else {
                //no resources for this page - setup an empty dropdown and inform the user none exist
                $linkerField = new DropdownField(
                   'DataObjectLightbox',
                   'Model Box',
                   array(
                      '0' => 'No ModelBox(s) for this page'   
                   )
                );
             }
             //insert the DropdownField
             $fields->insertBefore($linkerField, 'Description');
             $fields->insertBefore(new TextField('shadowboxWidth','Width', 490), 'Description');
             $fields->insertBefore(new TextField('shadowboxHeight', 'Height', 418), 'Description');
             //large image
             //$imageField=new TreeDropdownField('largeImage', _t('ImageViewer.IMAGE', 'Image'), 'File', 'Filename', 'Name');
             $imageField = new TreeDropdownField('largeImage', _t('HtmlEditorField.PAGE', "Page"),'SiteTree', 'ID', 'MenuTitle', true);
             $fields->insertBefore($imageField,'Description');
             //Youtube link
             $fields->insertBefore(new TextField('video', 'Youtube Video Link'),'Description');
    }
    return $form;
    }

    but there is some issue when these 2 lines of code is present,but when I comment out these 2 lines everything is fine, so it happens whenever I try to insert TreeDropdownField in the form :

    $imageField = new TreeDropdownField('largeImage', _t('HtmlEditorField.PAGE', "Page"),'SiteTree', 'ID', 'MenuTitle', true);
    $fields->insertBefore($imageField,'Description');

    I get the following error:

    ( ! ) Fatal error: Call to a member function FormAction() on a non-object in C:\wamp\www\sitetuners\framework\forms\FormField.php on line 161
    Call Stack
    #   Time   Memory   Function   Location
    1   0.0008   748128   {main}( )   ..\main.php:0
    2   1.2308   23704016   Director::direct( )   ..\main.php:189
    3   1.2512   25889528   Director::handleRequest( )   ..\Director.php:152
    4   1.2576   26056992   AdminRootController->handleRequest( )   ..\Director.php:360
    5   1.2975   29014360   LeftAndMain->handleRequest( )   ..\AdminRootController.php:93
    6   1.2975   29014360   Controller->handleRequest( )   ..\LeftAndMain.php:441
    7   1.7125   41963336   RequestHandler->handleRequest( )   ..\Controller.php:153
    8   1.7160   42019560   RequestHandler->handleRequest( )   ..\RequestHandler.php:222
    9   1.7655   45562848   RequestHandler->handleRequest( )   ..\RequestHandler.php:222
    10   1.7662   45566848   RequestHandler->handleAction( )   ..\RequestHandler.php:200
    11   1.7662   45567264   Form->forTemplate( )   ..\RequestHandler.php:288
    12   1.7662   45567792   ViewableData->renderWith( )   ..\Form.php:1319
    13   1.7835   48678720   SSViewer->process( )   ..\ViewableData.php:336
    14   1.8541   48695248   SSViewer->includeGeneratedTemplate( )   ..\SSViewer.php:1019
    15   1.8609   49264736   include( 'C:\wamp\www\sitetuners\silverstripe-cache\HEMANT-VAIO\.cache.framework.templates.Includes.Form.ss' )   ..\SSViewer.php:952
    16   1.9445   49756744   SSViewer_DataPresenter->XML_val( )   ..\.cache.framework.templates.Includes.Form.ss:63
    17   1.9445   49757240   SSViewer_DataPresenter->__call( )   ..\.cache.framework.templates.Includes.Form.ss:63
    18   1.9445   49757672   SSViewer_Scope->__call( )   ..\SSViewer.php:524
    19   1.9445   49758136   call_user_func_array ( )   ..\SSViewer.php:178
    20   1.9445   49758624   ViewableData->XML_val( )   ..\SSViewer.php:178
    21   1.9445   49758672   ViewableData->obj( )   ..\ViewableData.php:438
    22   1.9445   49758800   FormField->FieldHolder( )   ..\ViewableData.php:363
    23   1.9445   49759600   ViewableData->renderWith( )   ..\FormField.php:603
    24   1.9447   49761800   SSViewer->process( )   ..\ViewableData.php:336
    25   1.9456   49763128   SSViewer->includeGeneratedTemplate( )   ..\SSViewer.php:1019
    26   1.9475   49807528   include( 'C:\wamp\www\sitetuners\silverstripe-cache\HEMANT-VAIO\.cache.framework.templates.forms.CompositeField_holder.ss' )   ..\SSViewer.php:952
    27   2.2924   50147624   SSViewer_DataPresenter->XML_val( )   ..\.cache.framework.templates.forms.CompositeField_holder.ss:57
    28   2.2924   50148120   SSViewer_DataPresenter->__call( )   ..\.cache.framework.templates.forms.CompositeField_holder.ss:57
    29   2.2924   50148552   SSViewer_Scope->__call( )   ..\SSViewer.php:524
    30   2.2924   50149016   call_user_func_array ( )   ..\SSViewer.php:178
    31   2.2924   50149504   ViewableData->XML_val( )   ..\SSViewer.php:178
    32   2.2924   50149552   ViewableData->obj( )   ..\ViewableData.php:438
    33   2.2924   50149680   FormField->FieldHolder( )   ..\ViewableData.php:363
    34   2.2925   50150488   ViewableData->renderWith( )   ..\FormField.php:603
    35   2.2926   50152688   SSViewer->process( )   ..\ViewableData.php:336
    36   2.2936   50154008   SSViewer->includeGeneratedTemplate( )   ..\SSViewer.php:1019
    37   2.2956   50195704   include( 'C:\wamp\www\sitetuners\silverstripe-cache\HEMANT-VAIO\.cache.framework.templates.forms.FormField_holder.ss' )   ..\SSViewer.php:952
    38   2.2963   50197568   SSViewer_DataPresenter->XML_val( )   ..\.cache.framework.templates.forms.FormField_holder.ss:31
    39   2.2963   50198064   SSViewer_DataPresenter->__call( )   ..\.cache.framework.templates.forms.FormField_holder.ss:31
    40   2.2963   50198488   SSViewer_Scope->__call( )   ..\SSViewer.php:524
    41   2.2963   50198952   call_user_func_array ( )   ..\SSViewer.php:178
    42   2.2963   50199440   ViewableData->XML_val( )   ..\SSViewer.php:178
    43   2.2964   50199488   ViewableData->obj( )   ..\ViewableData.php:438
    44   2.2964   50199616   TreeDropdownField->Field( )   ..\ViewableData.php:363
    45   2.2979   50203424   ViewableData->renderWith( )   ..\TreeDropdownField.php:221
    46   2.2981   50205624   SSViewer->process( )   ..\ViewableData.php:336
    47   2.2991   50206944   SSViewer->includeGeneratedTemplate( )   ..\SSViewer.php:1019
    48   2.3011   50244264   include( 'C:\wamp\www\sitetuners\silverstripe-cache\HEMANT-VAIO\.cache.framework.templates.forms.TreeDropdownField.ss' )   ..\SSViewer.php:952
    49   2.3017   50246168   SSViewer_DataPresenter->XML_val( )   ..\.cache.framework.templates.forms.TreeDropdownField.ss:22
    50   2.3017   50246664   SSViewer_DataPresenter->__call( )   ..\.cache.framework.templates.forms.TreeDropdownField.ss:22
    51   2.3017   50246880   SSViewer_Scope->__call( )   ..\SSViewer.php:524
    52   2.3017   50247344   call_user_func_array ( )   ..\SSViewer.php:178
    53   2.3017   50247832   ViewableData->XML_val( )   ..\SSViewer.php:178
    54   2.3017   50247880   ViewableData_Customised->obj( )   ..\ViewableData.php:438
    55   2.3017   50247928   ViewableData->obj( )   ..\ViewableData.php:641
    56   2.3017   50248472   call_user_func_array ( )   ..\ViewableData.php:363
    57   2.3017   50248792   FormField->Link( )   ..\ViewableData.php:363

    Can anyone help what is wrong with the above code and how I can insert the TreeDropdownField in the LinkForm?? Thanks

    236 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.