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

I can add objects to DOM, but not edit them


Go to End


7 Posts   1724 Views

Avatar
theoldlr

Community Member, 103 Posts

11 January 2011 at 5:35am

Here is my DOM:

class VideoHolder extends Page {
         
        static $has_many = array(
            'VideoObjects' => 'VideoObject'
        );
   
   public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $datamanager = new DataObjectManager(         
            $this, // Controller
            'VideoObjects', // Source name
            'VideoObject', // Source class
            array(
                'Category' => 'Category',
                'Description' => 'Description',
                'YouTubeLink' => 'YouTubeLink',
                'URLSegment' => 'URLSegment'
            ), // Headings 
            'getCMSFields_forPopup'// Detail fields (function name or FieldSet object)
            // Filter clause
            // Sort clause
            // Join clause
        );
                //$datamanager->setPopupWidth('675');
                
                $fields->addFieldToTab("Root.Content.Videos",$datamanager);
                return $fields;
    }
       
   }

and my DataObject:

 class VideoObject extends DataObject {
       
      static $db = array (
        'Category' => "Enum('Auto Load and Unload, Cappers, DeCappers, Fillers, Leak Detection, Robotics, Washers', 'Auto Load and Unload')", 
        'Description' => 'Varchar(255)',
        'YouTubeLink' => 'Varchar(255)',
        'ShortCode' => 'HTMLText',
        'URLSegment' => 'Varchar(255)'
     );
     
     static $has_one = array(
        'VideoHolder' => 'VideoHolder'        
     );
  
  public function getCMSFields_forPopup()
  {
    return new FieldSet(
        new DropdownField(
            $name = "Category",
            $title = "Video Category",
            $source = singleton('VideoObject')->dbObject('Category')->enumValues()
        ),
        new TextField('Description','Description (text appears in link)'),
        new TextField('YouTubeLink','URL of YouTube Page')
    );
  }
  
   public function onBeforeWrite()
    {
        if($this->Description){
            $this->URLSegment = SiteTree::GenerateURLSegment($this->Description);
            if($object = DataObject::get_one($this->ClassName, "URLSegment='" .$this->URLSegment 
            ."' AND ID !=".$this->ID)){
                $this->URLSegment = $this->URLSegment.'-'.$this->ID;
            }
           // else {
                //$this->URLSegment = SiteTree::GenerateURLSegment($this->ClassName.'-'.$this->ID);
            //}       
        }
        if($this->YouTubeLink){
            $this->ShortCode = '[YouTube id="'.substr($this->YouTubeLink,strpos($this->YouTubeLink,"watch?v=")+8,strlen($this->YouTubeLink)).'"]';
        }     
        
        parent::onBeforeWrite();
    }   
     
  function ShowActionLink(){
        if($this->VideoHolder()){
            return $this->VideoHolder()->Link().'show/'.$this->URLSegment;   
        }
    }
 
  }

If the environment type is 'dev' I get a notice in the popup:
[Notice] Undefined index: start
GET /admin/EditForm/field/VideoObjects/item/1?SecurityID=11197/edit?ctf[VideoObjects][start]=0&ctf[VideoObjects][per_page]=10&ctf[VideoObjects][showall]=0&ctf[VideoObjects][sort]=&ctf[VideoObjects][sort_dir]=&ctf[VideoObjects][search]=&ctf[VideoObjects][filter]=

Line 139 in C:\website\cs\dataobject_manager\code\DataObjectManager.php

If environment type is not 'dev' I get the pop up, but the fields are not editable.

TIA

Luke

Avatar
theoldlr

Community Member, 103 Posts

25 February 2011 at 9:08pm

Edited: 27/02/2011 6:19am

I'm having this same problem again (can add but not edit) with a new error. This is a totally different install, different site, different everything actually. This time the Error is an SQL error:
"Couldn't run query: SELECT "StaffMember"."ClassName", "StaffMember"."Created", "StaffMember"."LastEdited", "StaffMember"."Name", "StaffMember"."Title", "StaffMember"."Bio", "StaffMember"."StaffMemberPageID", "StaffMember"."PhotoID", "StaffMember"."ID", CASE WHEN "StaffMember"."ClassName" IS NOT NULL THEN "StaffMember"."ClassName" ELSE 'StaffMember' END AS "RecordClassName" FROM "StaffMember" WHERE ("ParentID" = '2') Unknown column 'ParentID' in 'where clause'"

Anyone have ideas? I'm pretty sure the last time i fixed this by updating to a new verstion of DOM iirc. I'm now using r540, but no joy.
code below:

class StaffMemberPage extends Page{
	static $has_many=array(
		'StaffMembers'=>'StaffMember'
	);
	
	public function getCMSFields(){
		$fields=parent::getCMSFields();
		$manager = new DataObjectManager(
			$this,
			'StaffMembers',
			'StaffMember',
			array(
				'Thumbnail' => 'Photo',
				'Name'=>'Name',
				'Title'=>'Title'
			),
			'getCMSFields_forPopup'
		);	
		$fields->addFieldToTab('Root.Content.Staff',$manager);
		return $fields;
	}

class StaffMember extends DataObject{
	static $db = array(
		'Name' => 'Text',
		'Title' => 'Text',
		'Biography' => 'HTMLText'
	);
	
	static $has_one = array(
		'StaffMemberPage' => 'StaffMember',
		'Photo' => 'Image'
	);
	
	public function getCMSFields_forPopup(){
		$imageUploadField = new ImageUploadField(
			'Photo',
			'Photo to add:',
			array(
				'buttonText' => 'Upload an image'
			)
		);
		
		$imageUploadField->setuploadFolder('Images/StaffMembers');
		$imageUploadField->allowFolderSelection = false;
		return new FieldSet(
			$imageUploadField,
			new TextField('Name', 'Name:'),
			new TextField('Title', 'Title:'),			
			new SimpleTinyMCEField('Biography','Biography')
		);
	}
	
	function Thumbnail(){
		$Photo = $this->Photo();
		if($Photo){
			return $Photo->CMSThumbnail();
		}
		else{
			return null;
		}
	}

Also (and this may be part of the problem) my SimpleTinyMCEField looks like a SimpleHTMLEditorField--no toolbar with buttons etc.
Thanks!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

26 February 2011 at 3:52am

Mmm... do you see something wrong here?

static $has_one = array(
'StaffMemberPage' => 'StaffMember',
'Photo' => 'Image'
);

Avatar
theoldlr

Community Member, 103 Posts

27 February 2011 at 5:43am

Edited: 27/02/2011 6:10am

OBVIOUSLY! I guess thats what happens when you stay up way too late writing code.

My DOM is functional now, but the SimpleTinyMCEField still has no buttons. I'm getting a JS error in firebug that points to '$(function(){' in this script:

<script type="text/javascript">//<![CDATA[

      $(function() {
				$('#DataObjectManager_Popup_AddForm_Biography').tinymce({
  				  plugins : 'safari,paste',
  				  theme : 'advanced',
  			    theme_advanced_buttons1 : 'bold,italic,underline,|,justifyleft,justifycenter,justifyright,|,styleselect,formatselect',theme_advanced_buttons2 : 'cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,link,unlink,anchor,image,|,code',theme_advanced_buttons3 : '',theme_advanced_buttons4 : '',	  
  			   theme_advanced_toolbar_location : 'top',
      		 theme_advanced_toolbar_align : 'left',
      		 theme_advanced_statusbar_location : 'bottom',
      		 theme_advanced_resizing : false,
           paste_auto_cleanup_on_paste : true, 
           paste_remove_spans: true, 
           paste_remove_styles: true,      		 
  			   content_css : ''
  			   
		    });
		  });

//]]></script>

Nothing jumps out at me immediately here except that it mentions 'safari' and I'm using firefox. It is on a mac though.
Any ideas? Thanks!

Avatar
edski

Community Member, 12 Posts

14 March 2011 at 11:56pm

Hi,

I've got a similar issue with editing existing data objects.

I am using it for a number of things, incuding testimonials - very similar to the tutorial here: http://doc.silverstripe.org/old/modules:dataobjectmanager

Bizarrely, if I have more than one, I can use the prev/next buttons and edit the content in the popup fine. However, I can't edit the first 1 I click on. Any ideas?

class Testimonial extends DataObject
{
	static $db = array (
		'Quote' => 'Text',
		'Author' => 'Text'
	);
	
	static $has_one = array (
		'Page' => 'Page'
	);
	
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('Quote', "Quote (no punctuation)"),
			new TextField('Author', "Author name")
		);
	}
	
}

It's probably not best pratice, but I am extending my page class as I need to be able to add testimonials in across the site:

class Page extends SiteTree {
...

	static $has_many = array (
		'Testimonials' => 'Testimonial'
	);	

...
	$TestimonialDataManager = new DataObjectManager(
		$this, // Controller
		'Testimonials', // Source name
		'Testimonial', // Source class
		array(
			"Quote" => "Quote",
			"Author" => "Author name"
		), // Headings
		'getCMSFields_forPopup' // Detail fields function or FieldSet
		// Filter clause
		// Sort clause
		// Join clause
		);
		$fields->addFieldToTab("Root.Content.Testimonials", $TestimonialDataManager);

I can add them and get them to display fine - just the editing is not quite working as it should...

Thanks in advance.

Avatar
edski

Community Member, 12 Posts

15 March 2011 at 3:04am

I think I have tracked the issue down - it looks like it might be related to the SecureFiles module. The link in the edit buttons - and this is the same in the Files & Images section - is not correct:

/admin/EditForm/field/Testimonials/item/8?SecurityID=e26aa5351da9fe08e317cd0e6c681fef66f3c2e4/edit?ctf[Testimonials][start]=0&ctf[Testimonials]

For some reason it is adding the security ID element of the querystring in the wrong place.

Not sure how to fix it still :-(

Avatar
edski

Community Member, 12 Posts

15 March 2011 at 4:11am

FIXED!

It was after all an issue with the DataObjectManager. I saw this thread on Uncle Cheese's site:

http://www.leftandmain.com/silverstripe-modules/2010/09/01/uploadify-filedom-together-at-last/#comment-243

But actually saw that the latest version of DOM fixed it anyway. Installed that and all sorted...