3

I would really like to:

  • to create a paginated table of nodes, displaying only those that the user has 'update' permission to; displaying title, content type, and path alias

  • the path for nodes may be different depending on the content type. More specifically, I have created a content type 'file' to wrap an uploaded file; I would like to display the url alias associated to the actual file, rather than the url alias of node that wraps it.

There are a few approaches that I have considered,

  1. Creating views. However, the above behavior seems to require merging two views --- one for nodes of type file, one for node of content type not equal to file. I have no idea how to merge two views. Also, this method seems to create a dependency of the output of the view on the content type 'file'.

  2. Use database query + pagination. In many of the examples that I have seen, if I want to add pagination to a table, I can do the following (see this very excellent tutorial):

    • run a database query using either pager_query or the extend method for the SelectQuery object
    • theme the query results, and use theme to generate the pager based on the query

    The problem with this approach is making theme('pager') play well with filtering the database entries by node_access. For example, for an user with relatively few nodes that she can edit, the table displays many empty pages.

  3. Database query, filter into array, then use pagination on array as suggested by this post. This does get the table to work correctly. However, it is really expensive, because the entire query is run at this point, and the pager is purely for aesthetic purposes; seems a bit wasteful.

Now (thank you for bearing with me so far), is there a some way to create this table this without using views, but faster than method 3? I can also accept 'no' for an answer; in this case, it would be nice to know why not.

1 Answer 1

1

I realise the question is more than a year old...

Create a view with no content type filter. Add fields for Title, Type, Link, and File field in that order. In the Link field settings, check the Exclude from Display box. In the File field settings, under No Results Behavior, use the token of the Link field in the Rewrite Output space. The available tokens will be listed in an expandable space below the text field. Tokens include all fields listed before the current field, which is why the order matters. Set display to a table and turn on paging.

Views will automatically check access permissions, so this should do what you want. This will pull in all nodes, filter by access, look for the file and use that link if it finds it, and then in the cases where that field is empty (content of another type) it will use the node link instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.