Add CTools content type for stream

Michelle - November 3, 2009 - 02:13
Project:Facebook-style Statuses (Microblog)
Version:6.x-2.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I didn't make this a patch because 1) I don't know how to make a patch that adds directories and files and 2) you are almost certainly going to want to change names of things and help text and such. So consider this a rough draft.

This needs to be added to the .module file:

<?php
/**
* Implementation of hook_ctools_plugin_directory().
*/
function facebook_status_ctools_plugin_directory($module, $plugin) {
  if (
$module == 'ctools') {
    return
'plugins/' . $plugin;
  }
}
?>

That code tells CTools to look for the .inc files in [module_root]/plugins/[plugin_name]. In this case, it's "facebook_status/plugins/content_types". You can change this if you want.

This needs to go in a file named fbss_wall.inc and placed in the directory you defined in the last function:

<?php
/**
* @file
*   This file provides a CTools content type containing the author pane.
*/

/**
* Callback function to supply a list of content types.
*/
function facebook_status_fbss_wall_ctools_content_types() {
  return array(
   
'single' => TRUE,
   
'title' => t('FBSS Wall'),
   
'icon' => 'icon_user.png',
   
'description' => t('FBSS Wall.'),
   
'required context' => new ctools_context_required(t('User'), 'user'),
   
'category' => t('User'),
   
'defaults' => array('view_name' => 'facebook_status'),
  );
}

/**
* Output function for the 'facebook status wall' content type.
*/
function facebook_status_fbss_wall_content_type_render($subtype, $conf, $panel_args, $context) {
 
$account = isset($context->data) ? drupal_clone($context->data) : NULL;
 
$block = new stdClass();

  if (
$account) {
   
$block->title = t("Wall");
   
    if (
user_access('post on all profiles')) {
     
$size = variable_get('facebook_status_size_long', 40);
     
$block->content = theme('facebook_status_form_display', $account, $size, $conf['view_name']);
    }
    else {
     
$block->content = views_embed_view($conf['view_name'], 'default', $account->uid);
    }

   
$size = variable_get('facebook_status_size_long', 40);
   
$block->content = theme('facebook_status_form_display', $account, $size, $conf['view_name']);
  }
  else {
   
$block->content = "User information not available";
  }

  return
$block;
}

/**
* Returns an edit form for the custom type.
*/
function facebook_status_fbss_wall_content_type_edit_form(&$form, &$form_state) {
 
$conf = $form_state['conf'];

 
$form['view_name'] = array(
   
'#type' => 'textfield',
   
'#title' => t('View name'),
   
'#size' => 50,
   
'#description' => t('The relevant view should take one argument: the User ID of the user on whose profile this display will be shown. The facebook_status view is recommended if you don\'t know which one to use.'),
   
'#default_value' => $conf['view_name'],
  );
}

function
facebook_status_fbss_wall_content_type_edit_form_submit(&$form, &$form_state) {
 
// Copy everything from our defaults.
 
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
   
$form_state['conf'][$key] = $form_state['values'][$key];
  }
}

function
facebook_status_fbss_wall_content_type_admin_title($subtype, $conf, $context) {
  return
t('Wall');
}
?>

In each of those functions, "facebook_status" matches the name of the module and "fbss_wall" matches the name of the content type which is also the name of the .inc file. Feel free to change the name to whatever you like. Just make sure it all matches up.

You can get some more info on what the various bits mean here: http://shellmultimedia.com/articles/creating-content-type-ctools-panels-3

I'm hoping this can get into a release soonish because I want to replace the comment wall currently in APK with this.

Thanks,

Michelle

#1

IceCreamYou - November 3, 2009 - 02:54
Title:Add CTools content type for "wall"» Add CTools content type for stream

Great. I'm going to change some things around, namely using "stream" instead of "wall" and a select list instead of a textfield for choosing the view (see http://drupalbin.com/12210) but other than that I expect this to be in by the end of next weekend.

Also, I almost always patch things by hand anyway, so no patch is fine.

#2

IceCreamYou - November 8, 2009 - 21:49
Status:needs work» needs review

Committed, but not tested. It should work, but I'd appreciate a quick test to make sure nothing explodes.

#3

Michelle - November 10, 2009 - 04:00

It's not working for me on my site. I haven't had a chance to dig in and figure out why, yet, so this is just an FYI. I'll get back to you with a more usable report soon as I can. :)

Michelle

#4

Michelle - November 12, 2009 - 19:11
Status:needs review» needs work

I found the problem. You added a typo. :P

In function facebook_status_facebook_status_stream_content_type_edit_form change

$form['views_name'] = array(

to

$form['view_name'] = array(

After fixing it, I had to go back to the settings on the pane and put the view back in again. Having saved it once while it was broken nulled the setting. That shouldn't be needed for new users but you might want to mention it for people who have already tried to use the content type.

The NaN problem still remains, though. I don't know how to fix that one. :(

Michelle

#5

IceCreamYou - November 13, 2009 - 01:27
Status:needs work» fixed

Nice, it works for me now. Or at least it would if Panels/CTools didn't keep throwing an error in l() that makes every CTools page WSOD. Committing... the NaN problem is unrelated.

#6

IceCreamYou - November 13, 2009 - 01:36

Nice, it works for me now. Or at least it would if Panels/CTools didn't keep throwing an error in l() that makes every CTools page WSOD. Committing... the NaN problem is unrelated.

#7

System Message - November 27, 2009 - 01:40
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.