Failed relationship

  1. /**
  2.  * Plugin to provide an relationship handler for node from user
  3.  */
  4. function advanced_profile_panels_relationships() {
  5.   $args['node_from_user'] = array(
  6.     'title' => t("Profile node from user"),
  7.     'keyword' => 'profile_node',
  8.     'description' => t('Adds a profile node from user context'),
  9.     'required context' => new panels_required_context(t('User'), 'user'),
  10.     'context' => 'advanced_profile_panels_context',
  11.     'settings form' => 'advanced_profile_panels_settings_form',
  12.   );
  13.   return $args;
  14. }
  15.  
  16. /**
  17.  * Return a new context based on an existing context
  18.  */
  19. function advanced_profile_panels_context($context = NULL, $conf) {
  20.   // If unset it wants a generic, unfilled context, which is just NULL
  21.   if (empty($context->data)) {
  22.     return panels_context_create_empty('node', NULL);
  23.   }
  24.  
  25.   if (isset($context->data->uid)) {
  26.     // Load the node for the requested type
  27.     $uid = $context->data->uid;
  28.     $content_profile_node = content_profile_load($conf['type'], $uid);
  29.    
  30.     // Send it to panels
  31.     return panels_context_create('node', $content_profile_node);
  32.   }
  33.   else {
  34.     return panels_context_create_empty('node', NULL);
  35.   }  
  36. }
  37.  
  38. /**
  39.  * Settings form for the relationship
  40.  */
  41. function advanced_profile_panels_settings_form($conf) {
  42.   $options = content_profile_get_types('names');
  43.   dsm($options);
  44.   $form['type'] = array(
  45.     '#type' => 'select',
  46.     '#title' => t('Relationship type'),
  47.     '#options' => $options,
  48.     '#default_value' => $conf['type']
  49.   );
  50.  
  51.   return $form;
  52. }

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockcode>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Lines and paragraphs break automatically.

More information about formatting options