LemonStand Forum: Extending the blog post module with custom fields - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Extending the blog post module with custom fields

#1 User is offline   gcf 

  • Member
  • Group: Members
  • Posts: 27
  • Joined: 28-November 11

Posted 05 December 2011 - 01:33 PM

Hi all—

I'm running into a bit of a wall when it comes to extending the blog post module.

I've successfully added a "Featured Image" field, but I can't add a simple, varchar text field.

Here's my code:

public function subscribeEvents()
{
	Backend::$events->addEvent('blog:onExtendPostModel', $this, 'extend_blogpost_model');
	Backend::$events->addEvent('blog:onExtendPostForm', $this, 'extend_blogpost_form');
}

public function extend_blogpost_model($post)
{
	$post->add_relation('has_many',
					'featuredimage',
					array('class_name'=>'Db_File',
						  'foreign_key'=>'master_object_id',
						  'conditions'=>"master_object_class='Blog_Post' and field='featuredimage'",
						  'order'=>'sort_order, id',
						  'delete' => true
						  )
					);
		
	$post->define_multi_relation_column('featuredimage', 'featuredimage', 'Featured Image', '@name');
	$post->define_column('featured_link_text', 'Featured Link Text');
}
	
public function extend_blogpost_form($post)
{

	$post->add_form_field('featuredimage')->renderAs(frm_file_attachments)->renderFilesAs('single_image')->addDocumentLabel('Upload photo')->tab('Featured Image')->noAttachmentsLabel('Photo is not uploaded')->imageThumbSize(100)->fileDownloadBaseUrl(url('ls_backend/files/get/'));
	$post->add_form_field('featured_link_text')->tab('Featured Image');

}


To match, I've added a mysql update file:

alter table blog_posts add column featured_link_text varchar(255);


What am I missing here? The error I get is that "Render mode is unknown for featured_link_text field." But when I extend the product model, as long as the update file is there, I don't need to specify a render mode for the field.

Thanks!
0

#2 User is offline   gcf 

  • Member
  • Group: Members
  • Posts: 27
  • Joined: 28-November 11

Posted 05 December 2011 - 02:04 PM

Aha! Success. The problem was that in my version.dat file I had used a TAB instead of a space.

However, I still am having difficulty fixing the preview function, which puffs:

Quote

Form behavior: error in the model form elements definition. Tabs should be specified either for each form element or for none.


I couldn't find any reference to this problem online or in the docu.
0

#3 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,631
  • Joined: 31-October 09

Posted 06 December 2011 - 04:08 PM

Hi!

I'm not sure what causes the error. Please try to exclude your custom fields from the Preview page:

public function extend_blogpost_form($post, $context)
{
     if ($context != 'preview')
    {
        $post->add_form_field('featuredimage')->renderAs(frm_file_attachments)->renderFilesAs('single_image')->addDocumentLabel('Upload photo')->tab('Featured Image')->noAttachmentsLabel('Photo is not uploaded')->imageThumbSize(100)->fileDownloadBaseUrl(url('ls_backend/files/get/'));
        $post->add_form_field('featured_link_text')->tab('Featured Image');
    }
}

Thank you

#4 User is offline   gcf 

  • Member
  • Group: Members
  • Posts: 27
  • Joined: 28-November 11

Posted 07 December 2011 - 07:23 AM

Hi Aleksey.

Chopping them out does solve the problem, thanks!
0

#5 User is offline   Urvi 

  • Member
  • Group: Members
  • Posts: 22
  • Joined: 05-November 11

Posted 03 February 2012 - 05:51 AM

This Code is working fine for any module to extend with image field.

But how to display that particular image at front side?

For example here how can I display futuredimage at front side?

suggest me the simple way, without writing query on db_file table its possible !!

Thank you
0

#6 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 3,631
  • Joined: 31-October 09

Posted 05 February 2012 - 03:46 PM

Hi Urvi,

There are two free third-party modules on our Marketplace which extend blog posts with images and have documentation. Please check them out:

http://lemonstandapp.../featuredimage/
http://lemonstandapp...ule/blogimages/

Thank you

Share this topic:


Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users