Since blocks can't take arguments, creating a CTools content type will allow people to easily add this to custom pages. If you are interested, I'll do the coding for this one for you. If not, I'll just add it to APK. I need to do it for my own site. Might as well share. :)

Michelle

Comments

q0rban’s picture

I'm not sure what you mean by 'blocks can't take arguments', but I think you might be referring to this? #621538: Switch to using Views to allow greater flexibility

michelle’s picture

There is no way to pass an argument into a block. So if the code of the block requires some external information, it needs to pull it. This isn't ideal for use in custom Pages because the information may not be where the block expects it to be. But writing a CTools content type allows it to make use of the context on the Page.

This would handle the issue you linked to, if the site used a custom Page to display blog posts.

I've already written the code and have it working on my site. I just need to know if you want to include it in Follow of if I should toss it into Advanced Profile Kit.

Michelle

q0rban’s picture

I'd be interested in seeing the code.. Do you think this is a better way of doing it rather than turning it into a view? The nice thing about using views is you could pull all sorts of other user data into the same block display.

michelle’s picture

I don't see any benefit in making it a view but, then, I only need the simple block for my site.

This is the code for the content type:

/**
 * Callback function to supply a list of content types.
 */
function advanced_profile_follow_ctools_content_types() {
  return array(
    'single' => TRUE,
    'title' => t('Follow links'),
    'icon' => 'icon_user.png',
    'description' => t('Links from Follow module'),
    'required context' => new ctools_context_required(t('User'), 'user'),
    'category' => t('Advanced Profile Kit'),
    'defaults' => array('show_edit_link' => FALSE),
  );
}

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

  if ($account) {
    $links = follow_links_load($account->uid);
    if ($links) {
      $output = theme('follow_links', $links, follow_networks_load());
      
      if (!empty($conf['show_edit_link'])) {
        $output .= _follow_block_config_links($account->uid);
      }
    }
    else {
      $output = 'No links found.';
    }
  
    $block->title = check_plain($account->name);
    $block->content = $output;
  }
  else {
    $block->content = "User information not available";
  }

  return $block;
}

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

  $form['show_edit_link'] = array(
    '#type' => 'checkbox',
    '#title' => t('Caller'),
    '#size' => 50,
    '#description' => t('Check to show edit link on the pane.'),
    '#default_value' => $conf['show_edit_link'],
  );
}

function advanced_profile_follow_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 advanced_profile_follow_content_type_admin_title($subtype, $conf, $context) {
  return t('Follow links');
}

I put it in APK for now. If you'd like to use it in Follow, do this:

  1. Put the above code into a file named follow.inc
  2. Put follow.inc in follow/plugins/content_types
  3. Change the APK to Follow where appropriate in the code.
  4. Add this code to follow.module:
    /**
    * Implementation of hook_ctools_plugin_directory().
    */
    function follow_ctools_plugin_directory($module, $plugin) {
      if ($module == 'ctools') {
        return 'plugins/' . $plugin;
      }
    }
    

Michelle

q0rban’s picture

I don't see any benefit in making it a view but, then, I only need the simple block for my site.

Wait, isn't this the same Michelle that wanted it to have 'Online Status' in there as well? ;)

I was thinking having it be a view might kill two birds with one stone, allowing you to add other components to the block that you may want as well as having it be visible on pages other than user/%

Thanks for pasting the code, I will mess around with this soon. :)

michelle’s picture

Honestly, for my site, I really don't care about Online Status. But I plan to recommend this module for use with APK once the content type is settled into one of our modules and that's functionality that others have expressed interest in having.

As for making it a view, I really didn't look at that issue all that close. I'm doing 50 things at once and my only real issue is needing to get the block into a content type. :) A view is overkill for my simple needs but I don't think it's a bad idea if it helps others.

Michelle

q0rban’s picture

Status: Active » Closed (won't fix)

I'm going to set this to won't fix in favor of using Views.