I've just been thinking about ways to 'theme' the relativity links UI. I love the logic - just wanted to tweak the layout a bit.
here's a couple of crap illustrations:
eg with all perms:
node body ...
RELATED CHILD1s (remove)
+---------+----------------------------------+-----+
| child1a data ... [X] |
| child1b data ... [X] |
| child1c data ... [X] |
+---------+----------------------------------+-----+
[create new Child1] [attach old Child1]
RELATED CHILD2s (remove)
+---------+----------------------------------+-----+
| child2a data ... [X] |
| child2b data ... [X] |
| child2c data ... [X] |
| child2d data ... [X] |
+---------+----------------------------------+-----+
[create new Child2] [attach old Child2]
eg with only create_Child2_perms
node body ...
RELATED CHILD1s
+---------+----------------------------------------+
| child1a data ... |
| child1b data ... |
| child1c data ... |
+---------+----------------------------------------+
RELATED CHILD2s
+---------+----------------------------------------+
| child2a data ... |
| child2b data ... |
| child2c data ... |
| child2d data ... |
+---------+----------------------------------------+
[create new Child2] [attach old Child2]
My plan is :
1- embed a Page View (table) for each of the child node types (allowing me to pull in other node data fields).
* done (I think) see #13 in http://drupal.org/node/82415.
* a Block_View shouldn't be a very easy variation ...
2- display the 'remove ...' operator_links in a column in the view_table
* operator_link = 'relativity/unparent/$parent_nid/$nid'.
* Create a field_disown_child for Views ? by adding some functions to relativity_views.inc ?
3- apply user_permission_display rules to the whole 'remove ...' column.
* Not a clue. Even after staring numbly at the theme_functions in module and robert's patch (http://drupal.org/node/121207)
4- display 'create new ...' and 'attach existing ...' operator_links below each appropriate view_table.
* Well, I sort of hacked this in a PHPtemplate, but this bypasses the user-display-permissions thing :(
Please can anyone provide any pointers / advice?
many thanks, J
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | relativity_4.patch | 5.71 KB | owahab |
| #5 | relativity_3.patch | 4.52 KB | owahab |
| #4 | relativity_template.php_.02.patch | 2.5 KB | JohnG-1 |
Comments
Comment #1
JohnG-1 commentedproblems 2 & 3 completed! I hacked a (Node: Edit) function from views.module and spliced it into darius' relativity_views.inc. What this does :
It creates a views_field containing a 'Remove' link per node that severs the bond between the relevant child node and the current_view parent. (ie a 'themeable' remove_child link)
* In view/edit, add a 'Relativity: Parent Title' to your Fields list,
* Set the field's Handler option to 'Remove Link' (yes I know it's a rather ambiguous label ... suggestions welcome).
* The link is permission checked before it is displayed :)(code copied from "function views_handler_node_edit" in views.module v 1.166.2.6 2007/01/21 21:03:37 merlinofchaos)
patch: I can't write proper patch files but there are only 2 changes to relativity_views.inc:
First, find the handler array and insert the extra handler thus (note you can change the label here :)
Second, add this whole new function at the end of the inc file, after the other functions :
Tested: I've tested this with :
* a View_Table embeded into the 'parent' node (via it's node-parent.tpl.php)
... Now how on earth am I going to display 'create new ...' and 'attach existing ...' operator_links below each appropriate view_table ? ... any suggestions ?
Comment #2
JohnG-1 commentedGot it :)
see a demo at my sandbox site : http://oneirica.com/test_relativity/node/14
First: make sure you apply the previous #1 patch to relativity_views.inc - or you'll lose the 'Remove child' links altogether ;)
Second: you will need to make a separate View for each content type involved in the relativity system, and name it 'childview_$type' (where $type is the name of the content type) - or you'll get 'foreach()...' errors if it can't find the view. The childviews need to be set up like this:
I'm going to use Folicle as an example node type so you can see how the labels work.
and that's it!
now save this view and clone it. Edit each clone, changing all 3 occurances of Folicle to the name of the next node type;
Third: Add this one-drop patch to your template.php (ie it only works with PHPtemplate themes - only tested on Garland 5.1). All it does is 'change' 2 Relativity theme functions: theme_relativity_show_children and theme_relativity_links. it doesn't touch parents or ancestor links...
whew!
next I'll start on the 'Parent nodes' links to see if we can't make a pager ... ;)
Comment #3
JohnG-1 commentedoops i missed the close bracket off the above patch function :P
at the end it should read:
sorry about that
Comment #4
JohnG-1 commentedI've added a couple of error checks for more harmless integration of the theme code that goes at the end of your template.php.
1. theme code now checks that views.module is installed and active, if not it skips the phptemplate_theme functions, allowing relativity to use it's normal theme_functions.
2. if a childview_$type is missing or misnamed (ie if you haven't set up a childview_* for a particular node type), you get a helpful, inline error message rather than the views errors you used to get :)
3. the patch for relativity_views inc (above) is still current, and you will need it to provide the 'remove' links for detaching children to your childview_*
so now it's just alot more friendly ... if it can't find the bits it needs, it doesn't fall over :)
there's a full demo and some notes on my testsite : http://oneirica.com/test_relativity/node/14
feedback most welcome.
Comment #5
owahab commentedI actually thought about this in a different way: why not allow relativity to render children of type "foo" using a view created with views module. This allows for enormous flexibility.
I have just finished writing the code and I tested a little bit.
Feedback is welcome.
Comment #6
JohnG-1 commented#5 : relativity_3.patch: Omar - you beauty!!! This is a huge improvement! I had also been thinking about how to build the views option into the display options, but I wasn't really sure where to start - but you've done it for me with perfect timing too :) Thank you !!!!
OK so I have applied relativity_3.patch to a clean
$Id: relativity.module,v 1.36.2.1 2007/02/10 05:20:27 darius Exp $, using an unpatched relativity_views.inc. Have I got that right? or should relativity_3.patch go on top of other patches? Anyway, here are my observations of the relativity_3.patch only results (where '@' = good new feature, '+' = problem):Views integration
@ This patch to relativity.module creates new Rendering option for children nodes of type ... , to display children as a View - it even gives you a list of your views to choose from.
@ It displays a separate list or table of child-nodes for each node-type.
+ When applied to a Full Nodes or Teaser List View it's not very happy ;) (but I can't think of a reason to use these options anyway ;)
@ When applied to a Calendar View it plays quite nicely ... :)
Link Operations
@ When applied with a Table or List View it also displays a field containing Remove links for each child, and Create new ... link nicely below the table.
+ Neither these new Remove links nor their containing field are permission checked ... everyone has access to the Remove links.
+ Restricting the View Permission (admin/build/views/#child_view) does not hide the #child_view from unauthorised users at all.
+ When applied with a Table or List View it does not hide the Link Operations fieldset, duplicating the Remove Create new ...and links.
Views Arguments
+ (First) View Argument Handler set to Relativity: Parent Node ID (display all values) does not filter the list. I assume this is because the parent node is not passing its parent_nid to the embedded view.
+ (Second) View Argument Handler set to Node: Type (display all values) ... as relativity_3.patch builds a view for each child node-type, it would be useful to pass the node-type as an argument as well.
+ My guess is the following code should go at the top of the
function theme_relativity_links(but that isn't working for me ... )I'll keep tinkering with this, but in the mean time any pointers are most welcome :)
Comment #7
owahab commentedI didn't think anyone will like the patch to that extent, anyways I have made some fixes for some issues you mentioned since they were known bugs for me.
I have fixed the following with the last patch:
- Permission check for Remove and Attach links.
- Commented out the original Attach/Remove code to show links once.
- Added the parent node type as the second parameter.
- Added the child node type as third parameter.
And the following bug was found in views module:
- Views can't handle sorting when more than one view are rendered in the same page so you end up with disabling sorting in your embeded views.
Comment #8
JohnG-1 commentedOmar you continue to make drupal slightly less infuriating ;)
This patch is superb - thank you!
I did struggle to configure the view argument handlers - I almost doubted your genius ;)
But I've cracked it now :) This is how I explained it to myself ...
I'm working on a generic Relativity_children view which could be rolled into the module / patch as a default view.
It's delayed because I haven't got the Argument Handling Code for the Block View working. Page View works fine :)
Comment #9
JohnG-1 commentedOmar's patch (which now has a thread of it's own http://drupal.org/node/130870) is definitely a better approach than most of the stuff on this thread, so I'm to close this issue and relegate it to history.
I hope nobody minds. ... and a huge thank you to Omar :)
Comment #10
jlalvarezmedina commentedI've been trying hard to apply the different patches I saw, with no success :(
So I tried to solve the problem on my own. And I found a way around :)
I took the official 2.x version, and I did the following modifications:
I un-commented the following block in relativity.module
/*
// the $view will maintain its field contents, so I wanna make sure
// I will add the extra field only once..
static $fields_count;
$fields_count = count($view->field);
$view->field[$fields_count] = array(
'vid' => count($view->field),
'tablename' => 'node',
'field' => 'nid',
'label' => '',
'handler' => 'relativity_handle_view_links',
'sortable' => 0,
'defaultsort' => 0,
'fullname' => 'node.nid',
'queryname' => 'node_nid',
);
*/
Then, I changed the function relativity_handle_view_links in the same module, by replacing the $parent variable, in this case, meaning the parent node ID (it was being obtained directly from the relativity table starting from a child node ID, but this is wrong as a single node may have many different parents) and took it from the right parent. So I took it from a safe place: the URL :)
function relativity_handle_view_links(&$field, &$view, $nid, &$node){
$parent_nid = arg(1);
if (relativity_may_unchild(node_load($parent_nid), $node)) {
return l(t('remove'), 'relativity/unparent/'. $parent_nid .'/' . $node->nid);
}
}
with this two small changes, I solved it. Now I can remove the "link operation" block, or at least the ugly "remove" links on it
Comment #11
jlalvarezmedina commentedIf someone knows about some problem that could emerge from this changes, please let me know