Closed (fixed)
Project:
Neologism
Version:
7.x-2.x-dev
Component:
Code
Priority:
Major
Category:
Task
Assigned:
Reporter:
Created:
16 Jun 2011 at 18:22 UTC
Updated:
30 Aug 2011 at 11:51 UTC
Jump to comment: Most recent, Most recent file
Firstly great to see that we can now mark issues as 7.x..
I have been able to assign URL Alias to the vocabulary hosting page as the Namespace URI provided by users.
However, now I would like to customize this page by -
1. including links to add class and property.
2. Showing the vocabulary structure on the page (existing classes and properties)
3. adding buttons to import the vocabulary in various formats.
etc.
I tried reading around but could not figure out a way to do so without altering files outside the Neologism folder. Any clue how to go about doing this ?
Can i place the node--vocabulary.tpl.php theme inside the Neologism module folder and make it work? Or any other way?
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | workspace-page-1190784-18.patch | 6.75 KB | mayankkandpal |
| #17 | workspace-class-property-1190784-17.patch | 4.25 KB | mayankkandpal |
| #9 | links-1190784-9.patch | 4.52 KB | mayankkandpal |
Comments
Comment #1
cygri commentedHi Mayank, I can only explain how we made this work in D6, I'm not sure what part of this applies to D7.
The node-neo_vocabulary.tpl.php is only used when a vocabulary is rendered on the homepage. It's not used for the vocabulary overview page.
Regarding links for adding classes and properties, and importing. This is all done via the menu system. Look at neologism_menu, which is really at the heart of the entire module:
http://code.google.com/p/neologism/source/browse/branches/drupal-6/neolo...
I'll describe the logic for rendering the vocabulary overview page. This is all in the /branches/drupal-6 codebase.
In neologism.module, neologism_menu_alter changes the default page callback for viewing nodes to a custom page callback that does content negotiation for vocabularies. This is a bit of a hack.
http://code.google.com/p/neologism/source/browse/branches/drupal-6/neolo...
The custom callback checks whether we actually are looking at a vocabulary overview page; and if that's the case, then it checks which content type was requested:
http://code.google.com/p/neologism/source/browse/branches/drupal-6/neolo...
If it's HTML, then neologism_export_html is invoked. It's in neologism.theme.inc, for no very good reason (it doesn't really use the theme system):
http://code.google.com/p/neologism/source/browse/branches/drupal-6/neolo...
Comment #2
Anonymous (not verified) commentedI think I'll need to be pretty involved in helping you with this, Mayank. If you have a patch that assigns the url alias to the vocabulary, send me the link to it and I'll apply it to see what you've done so far. I'm pretty sure we'll want to move in a different direction than the existing way of doing it in Drupal 6.
I believe the appropriate way to do this would be to use a render array. The form API uses render arrays. You can also use them to put pages together. Check out Examples module. There is a render example there.
Comment #3
cygri commentedI guess a render array would indeed be a better approach than the string building mess we currently do in neologism_export_html. On the other hand, anything that works is a step in the right direction … and I thought that the main issue for now was to find the right hooks for customizing the vocabulary overview page at all.
Comment #4
mayankkandpal commentedLin, I have the current latest patch at http://drupal.org/node/1196510#comment-4696374
It does assign url aliases for vocabulary.
I will check out the Render example asap!
Comment #5
mayankkandpal commentedFor reference, this is a list of fields which is currently being displayed on the workspace page and the list of fields/links that are additionally needed there :
Fields currently showing :
Fields/ Buttons required additionally :
- abstract
- body
- additional custom RDF
Once the class and property fields are added, we also need to show :
Later on, we also need to put buttons to import external vocabularies to the workspace, and then display them as links on the page.
Comment #6
Anonymous (not verified) commentedOne way that would be worth trying is copying Field Collection. Field Collection creates a separate entity for each collection, but displays them on the main node and also gives you an add button.
This would not solve 1. or 3., but I think it's worth giving it a shot and then posting a patch here.
Comment #7
mayankkandpal commentedI have been trying to get the Add class and Add property links on the vocabulary workspace page. I have tried out two methods for that -
1. Using Render Arrays - Failed
Initially I thought of adding add-class and add-property links on the navigation menu which contains the View, Edit and RDF links. I used hook_page_alter() and tried to dig deep into the array structure and locate these items. However, the code for that particular navigation is not appearing in the $page which is passed to hook_page_alter() and instead, it simply renders a predefined navigation in the code. So I cant modify that menu and add new links.
2. Using Field Collections - Working
I tried to add field collections to the vocabulary workspace page through the UI, and it does provide an add link to the vocabulary workspace and it looks good for our purpose.
However, while saving the field collection, I would need to create a class/property node as well, so I will have to probably hack into the function which saves the class and property and save the class node, so I would need some more time for that. What do you think ?
I can roll a patch which provides add-class and add-property links on the workspace page without actually creating the nodes in the backend for now. Should I do that ?
Also, should I continue to use the Field collections (which adds 2 more dependencies for Neologism, ie, Entities API and Field collection module) or are there any more ways that I should explore ?
Another problem that I am facing is in defining links in hook_menu(). I was trying to define links of the type $items['node/%neologism_vocabulary/add-class'], which is expected to return render the class_node_form(). The drupal-6 code for the same is not working anymore, and some other ways I tried also didnt work. However, I will try to look deeper into this and get it working.
Comment #8
mayankkandpal commentedThe hook_menu() method for displaying Add class/property links is working.
Add class and Add property links are available on the main Vocabulary node page at the moment, and a link to the main vocabulary node page is available on the vocabulary workspace for now.
In the Class and Property node forms, the 'Related Vocabulary' fields are hidden from the users now. When we save a class/property, the 'Related Vocabulary' field is automatically populated in the backend, and the link between vocabulary and class/property is created.
So now we have a link from vocabulary workspace to main vocabulary and from main vocabulary to its classes and properties.
However, whevener we save the class/property, the following notice pops up :
This is probably because we are returning FALSE in the following two condition inside the module neologism_load()
Trying to get rid of this pop up notice now.
Comment #9
mayankkandpal commentedPatch for displaying add-class and add-property links on vocabulary node page.
Known issues :
1. Menu system is heavily cached so one may need to 'Clear all caches' just once after applying the patch
(Configuration » Development » Performance -> Clear all caches). After this, the add-class and add-property links appear on vocabulary page.
2. The Notice mentioned in the above comment still pops up on saving class/property.
Comment #10
cygri commentedGreat! Don't worry about the caching issue, it's normal to manually empty the cache whenever something has changed in the menu system. The notice is caused by the ampersand (&) in front of the function name. Adding this ampersand was meaningful in PHP4, but is unnecessary or even harmful in PHP5, so there is no good reason for it to be there. I just removed it in the patch.
The patch (without the ampersand) is applied in http://drupalcode.org/project/neologism.git/commit/bdf4482 and I'm closing the issue.
Comment #11
mayankkandpal commentedI reopened the issue since there is bit of work still left here :)
I have figured out a way to dynamically update the vocabulary overview page, but there is a problem with my approach.
I plan to use hook_node_insert() which would be invoked each time a node is added. I would then check if the node type is class /property and then update the body of the vocabulary workspace using the $node parameter which is passed to the hook function.
However, the problem here is data duplication. If the user decides to edit the class/property, then there might be issues. We can use hook_node_update() which respond to updates to a node, but there might be a lot of loopholes this way.
Any suggestions ?
Comment #12
mayankkandpal commentedI think i figured out a way to correctly handle the data duplication. The data will be added to the vocabulary overview page as follows :
1. Install two fields in the vocabulary workspace entity:
2. Set display settings such that it is hidden in teaser mode and visible in default mode.
3. Set the '#access' attribute to false to hide these fields from the users while the vocabulary workspace form is presented.
Thus, these fields will not be visible to the users but we can dynamically populate them and make them visible on the vocabulary workspace page.
4. The links to add class and property already appear on the vocabulary node page. Add new class/property through these.
5. Define hook_node_insert() which accepts $node parameter and is invoked whenever a new node is created.
6. Inside hook_node_insert(), check if the $node->type is class/property.
7. If it is class/property, then get the id of the vocabulary to which it is associated using
8. Use the 'nid' of vocabulary to get the 'nid' of the related Vocabulary workspace node, using
9. Load the vocabulary workspace node
10. Edit the workspace_class_space/workspace_property_space field of this node, whichever is appropriate.
Here, each new entry will be added in a div which will have the id equal to node id of the class/property so that it can later be identified and updated when the user wants to make changes. When the user makes changes to already existing class/properties, then we will use hook_node_update(), which respond to updates to a node.
11. Save the vocabulary workspace node.
Hope I make some sense here :) Data duplication is unavoidable but hopefully this should be able to correctly handle it during insert/update.
Comment #13
cygri commentedWow, you really dug into this :-)
What you describe would probably work, but yeah it would be necessary to carefully synchronize the fields on node_insert, node_update, node_delete and so on.
Lin and me discussed about how the duplication could be avoided, and I think it's possible. The key idea is to use hook_node_view to alter what's displayed on the vocabulary overview page, and render a teaser view (kind of like on the homepage) of all the classes and properties belonging to the vocabulary. Here's how it might work:
1. Use hook_node_view to customize the display of the vocabulary overview page
2. Use EntityFieldQuery to find the classes and properties that are related to this vocabulary
3. Use node_load_multiple, followed by node_view_multiple in teaser mode, to render the nodes
4. Add the rendered nodes to the $node->content render array in hook_node_view
This should be enough to put the classes and properties onto the vocabulary overview page.
This comment here shows an example for steps 2-3:
http://drupal.org/node/916776#comment-4191166
Now, I'm not sure if the teaser view mode will display a class/property in exactly the way we want. So the next step might be not to use the teaser view mode, but to add a custom view mode. This is explained here:
http://mearra.com/blogs/juha-niemi/drupal-7-custom-node-view-modes
But in the interest of time, I'd say that this custom view mode is optional for now. For future reference I'll note that in D6 we didn't create a custom view mode, but just overrode the default view mode, which isn't really the right way of doing it. This means we already have a custom preprocessor function and theme function for nodes in the D6 version, they could be used as starting points for the custom view mode:
http://code.google.com/p/neologism/source/browse/branches/drupal-6/neolo...
http://code.google.com/p/neologism/source/browse/branches/drupal-6/neolo...
(Note: You may have already seen this but in researching the above, we noticed some interesting code in field_collection.module around line 680, it shows how a custom link can be added to a page using render array logic. This might have been a solution for putting the "add class/property" links onto the page. You've already solved that issue, but the technique might come in handy at some point in the future.)
Comment #14
mayankkandpal commentedThis is a Great way ! Working on the patch.
Comment #15
mayankkandpal commentedI wrote down a crude code for testing out the method and it seems to work fine except that i haven't yet figured out where to append the render arrays on the workspace page. At the moment, the classes are prepended to the page, i.e. they appear before all the other stuff in $node->content. I will need to figure out the page structure and place the
Comment #16
cygri commentedOne thing you could try is adding a
#weightproperty to the new element that is added to the array. See here:http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....
Comment #17
mayankkandpal commentedPatch for adding class and property info. on the workspace without data duplication.
Weights were employed to place the data properly.
Suspending the remaining part of issue for now in the interest of time and working on RDF output.
TODO:
1. Create custom view mode.
2. Creating headings separating class and property.
3. Should we add more information about the Main vocabulary on the workspace page?
I had created a custom view mode before so if I get the time I would try to work on that.
For creating headings which say "Main vocabulary Classes" and "Main vocabulary Properties" on the Workspace page, I tried to use the #title attribute (just like I have used the #weight attribute) but it didnt work out.
Development switched to #1242076: [D7 Port] Port the RDF output to D7
Comment #18
mayankkandpal commentedThe workspace looks much better now with this patch.
Patch fixing following bugs :
1. Added links to the workspace to :
2. Added headings Main Vocabulary Classes and Main Vocabulary Properties separating class and property.
3. In the Add-class and Add-property forms, the prefix for URI now appears correctly populated with the vocabulary-id :
eg. http://.../foaf# instead of http://.../vocabulary-id#
Also, shouldn't we remove the rdfx dependency from .info file ?
Comment #19
cygri commentedWe'll need the ARC2 library for the RDF output. ARC2 comes with rdfx (well you still have to install it, see the README of rdfx).
I didn't get a chance to review the patch today and will be out of town tomorrow; will have a go at it on Monday.
Comment #20
mayankkandpal commentedfixed