Drupal Views: Adding Edit button and other buttons per item - drupal

I've setup a view in drupal that lists items like this:
IMAGE 1 | IMAGE 2 | IMAGE 3 | IMAGE 4
desc | desc | desc | desc
where "desc" is, you guessed it, a description of the node. What I need is to end up with something like this:
IMAGE 1 | IMAGE 2 | IMAGE 3 | IMAGE 4
desc | desc | desc | desc
EDIT | EDIT | EDIT | EDIT
ACTION | ACTION | ACTION | ACTION
Where EDIT goes to the edit page of the various nodes. Also, the ACTION signifies a button that I want to appear underneath the items that navigates to a page, let's call it http://www.mysite.com/action and takes the id as a parameter to end up with something like this: http://www.mysite.com/action/1.
I hope this all makes sense.
The pain in the ass way to solving this is to create a theme file views-view-NAME.tpl.php and manipulate the $rows variable. I just think there must be a better way and I'm obviously just missing something.
So, does anybody know how to do this?

You can add links and then style them as buttons (if you really need it to look like a button) by doing something like this:
Add the following fields to your view:
Node: Edit Link (this will take care of permissions for you, only displaying a link for users that have access to edit)
Node: Nid
In order to get that second field to be an arbitrary link containing the node ID, select the Output this field as a link option when configuring the field. In the Link path box, enter the desired link, something like this:
action/[nid]
or, you can use an absolute url
http://www.example.com/action/[nid]

For Drupal 8, I built the Views Any Route module, which lets you create buttons based on routes: https://www.drupal.org/project/views_any_route . The main use for the module is that access checking is included in the construction of the link, which would otherwise require a custom field, or Views Field View, etc.
In this case, if you use the Devel module, you can look up the "routes info" and find the correct route for a node path. You then create the Any Route button for that route, and pass the nid as a parameter (i.e. node={{ nid }}).

Related

How to create a table like structure in drupal content type?

I am almost there with this but cannot seem to get this functionality going as planned.
I am creating a questionnaire using drupal content type. What I am trying to do is to create a table like structure as below in content type. The second and third column contain check boxes and first column data(i.e computer, internet) and first row(i.e Everyone have access , Nobody have access) are taxonomy terms . Is it possible to display like this in content type by using some modules in drupal? Anybody have any better suggestions?
| | Everyone have access | Nobody have access |
---------------------------------------------------------
| Computers | 1 | 2 |
---------------------------------------------------------
| Internet | 1 | 2 |
---------------------------------------------------------
| Fax | 1 | 2 |
---------------------------------------------------------
You can use the Term Level Field module. This module provides a field type for referencing terms with a level to an entity.
You may use Editable fields with Views module. Of course, if you didn't need such a display (table forms) you should use Views Bulk Operations modules.
If you need to do this in a node use Tableform module. But if you want to show nodes whike editing a node it is the same. A node should not be used for tasks just for content.

Drupal Webform. Embed nodes with a specific content type

I want to create a form where the user can order some publications from a site,
where the available publications is loaded/embedded automatic from the system (nodes with a specific content type).
I have created a Webform with some basic fields: Name, Email...
How do i add a field reference to these publications?
Like:
Name : ____________________________________
Email : ___________________________________
Publications :
Publication 1 Quantity ___
Publication 2 Quantity ___
Your solution would be to add a webform component that acts as a node reference, perhaps this can help.

Plone 4: List members that have been given Reviewer role on a specific folder

I've created a new view for a folder (based on Tabular view) the only the Title and Date for regular viewers, but if the logged in user had the "Editor" role, it shows an additional column. That column needs to list the users who have been given "Reviewer" role to that specific item. For instance, the columns would be:
Title | Date | (Reviewers)
Folder 1 | 10/04 | Johnny, Steve, Mary Sue
Folder 2 | 10/13 | Sam, Betty, Johnny
I've been able to hide/show the final column based on the authenticated user's role, but I can't seem to figure out how to list just the users who have reviewer access. I've tried using searchForMembers(), but in addition to being very slow, I can only get it to echo the entire list of Members, or narrowed based on site-wide roles, but I need to get just people who have been manually given Reviewer role on the specific folder.
Here's the code for the entire column:
<td tal:define="is_manager python:test(here.portal_membership.getAuthenticatedMember().has_role('Manager'), 1, 0);"
tal:condition="is_manager">
<tal:block tal:define="results python:item.portal_membership.searchForMembers(roles=['Member']);">
<tal:block tal:condition="results"
tal:repeat="user results">
<tal:block tal:define="fullname python:user.getProperty('fullname')">
<span tal:replace="fullname">Full Name</span><span>, </span>
</tal:block>
</tal:block>
</tal:block>
</td>
It works when I have roles=['Member'], but if I change it to "Reviewer" I get nothing - I think because nobody is assigned as a Reviewer for the entire site, only for specific items. I've also tried using .listMembers() in various ways, but it seems that's restricted and I can't use it in the page template. Is there a way around this, or is this the "wrong way" to go about this in the first place?
I've answered to a nearly identical question 2 day ago:
List folders that a user has Reviewer access to in Plone 4
the updated code should look like this:
from Products.CMFCore.utils import getToolByName
portal_url = getToolByName(context, "portal_url")
portal = portal_url.getPortalObject()
acl_users = portal.acl_users
res = []
local_roles = acl_users._getLocalRolesForDisplay(context)
for name, roles, rtype, rid in local_roles:
if 'Reviewer' in roles:
res.append((name,roles,rtype,rid))
I'd suggest to put this kind of logic in the file python and not in the page template.

Drupal 7: Displaying nodes by grouping them based on a field

Is there a way to group nodes based on a node reference field and display them in a list.
Say, I have a content type Album, and nodes Album ABC and Album DEF of type Album. These are referenced in nodes of content type Track. How can I display all the albums with the referenced Tracks in which they are referenced as a list?
For example:
Album ABC
Track 1
Track 2
Track 3
Album DEF
Track 4
Track 5
Track 6
and so on.
I have been using Drupal only for a few weeks now, Can anyone explain the answer given below??
Thanks.
Create a view filtering on the node type = album
Set the view output style to "HTML List"
Include the node reference field as a link to node in your field list
Click "theme information" then look at the name of the file that applies to the node reference field. Create a .tpl.php file with a candidate name that's specific enough for your needs will be something like views-view--viewname--fieldname.tpl.php. Click the link for the template file in use in theme information for this field, and views will show you the code in that file. Copy & paste that code to your new file
In the new file, you'll want to write a little PHP to output your links as a list. If you enable the devel module, put in the page, and inspect what's available. One of them will be an array of links. Output that with
Try Field Group or Display Suite.

Submitting form custom module

I have a question regarding drupal 6 forms.
I have 4 tables:
location[locationid, name];
package[packageid, name],
person[personid, name, locationid, address, etc...]
pickup[pickupid, personid, packageid, locationid, _pickup_day_,...].
I've made forms and form_submit for the three tables: location, package, person (simple CRUD as usual).
Now, I want to make a form to submit data into the "pickup" table. The twist is, the only
data the user needs to input is the "pickup_day" field, which can be 1 or 0 (monday or tuesday).
So I imagine when I go to the pickups url, I'll see a list of output fields:
firstname | lastname | location | pickup day | package type
first1 last1 church1 select box (monday/tuesday) select box (type1/type2/type3)
first2 last2 church1 select box (monday/tuesday) select box (type1/type2/type3)
first3 last3 church1 select box (monday/tuesday) select box (type1/type2/type3)
[submit button]
When its submitted, the data goes into "pickup" table.
I'm trying to figure how to render the select boxes while outputting person's information.
(Just an aside, would it be possible to have a search before seeing the form...for example I search for
location to be church1, then I'll see all the users at that location in a form as above)
All help is very much appreciated...even pointing to a module that does something similar to this is fine...
I just need to get some hints on how people have approached this. Much thanks!
End goal:
So, basically, I have a number of people in my database. Each person is assigned a location where they can go and pickup food. I want to record each pickup for each week for each person. So I have a pickups table to do that. So I'm trying to make a single form (pickups), where I can go to and update who picked up what...on what day (Monday or Tuesday). But so in this form, I need to show all the people registered for a particular location. So lets say a person is registered for a church called Church 1...I want to search for the Church 1 location, then all the people who are registered for that location comes up row by row. Then I can select which day each person picked up food and what type of food they picked up...and click submit. Then I'll run a query against my database to add this information.
The big deal I guess is that instead of making a form for each person (for each row), I just make one form and when the form is submitted everyone will be added to the "pickup" table with the appropriate day and item they picked up.
I would suggest you look at the form API's built-in AHAH support. You can find more information here: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#ahah. Assuming I understand your question correctly, this is a fairly typical ajax/ahah form situation; an element in your form triggers the creation of new form elements.
For example, you can create a select box of locations. Once a location is selected (#ahah['event'] => 'change'), you can make a callback to a menu location (#ahah['path'] => path/to/callback) which can generate the new form elements to add, in this case select boxes for the persons and/or packages associated with that location.
You could also do something similar using search instead of a select element.

Resources