By daviesap on
Hello -
I hope I haven't missed something. Have done a good search around the forums though. Am new to Drupal.
I have made a content type for a list of data, and now a view with it filtered, sorted and displayed just how I like it.
But adding and editing content shown within the view is rather tedious. To add content I have to go Create Content, select content type etc. Similar thing with edit.
What I would like is to be able to add, edit and delete content directly from the the view (which is linked to a menu).
Apologies if this is a basic thing and I have missed something.
Many thanks,
Andrew
Comments
You can add edit and delete
You can add edit and delete links for individual records on a view for users with the correct permissions (Fields - Node: Edit Link & Node Delete Link).
An Add content link can be added via a Views Attachment.
Many thanks SweenyTodd. I've
Many thanks SweenyTodd. I've got those edit and delete links working now. Perfect!
Can't work out the Views Attachment though.
Do you mean the module at https://drupal.org/project/attachment_links or adding an "attachment view" through the views UI?
Thanks again
My mistake
Sorry Andrew,
I thought this could be done in Views Attachments but it I had a look and could not see a way to do it.
Here is another way.
First make sure you have the php Filter module enabled (Administer > Modules). It is listed under Core (optional).
This will enable php snippets to be used as one of the input formats when you are adding content.
Go back to your View.
Under basic setting on the View, you will see a field called Header. Make sure the input format is set to php and you might want to enable the output even if the View returns no results.
The following code produces a link to add a Page content type. You will have to modify it for the content type required:
A quick run through of what the code does:
1) accesses the global $user object which stores info about the current logged on user.
2) checks whether the current user has permission to 'create page content'. You will have to modify this for another content type. The text should be the same as on the permissions page and should be of the form 'create xxxxx content'. Instead of using the permissions table, you may way to display this only for a particular role, or limit it to $user->uid = 1 for the super-user (admin) account.
3) creates a link with text 'Add new page' to the url listed. The l() function is built in to Drupal to build links (see http://api.drupal.org/api/l/6), you can also add classes to the link with this as well for css styling. The t() function just makes the 'Add new page' text available to Drupal's in-built translation tools - probably not necessary for a private site, but good practice anyway.
That's great! Thanks so much
That's great! Thanks so much ST. Trawled for hours last night trying to work it out - had it going within 10 minutes with your post.
My next challenge (probably one for another day!) is to have form underneath the views output, which when filled in and submitted adds the content.
Good luck with the job search.
Thanks again,
Andrew
I haven't done it before but ...
I haven't done it before but ...
Add Drupal.behaviors to the page via a js script - the script file can be added in the theme .info file. Use this to add a click even to the link. If the script fails to run then the functionality will revert to changing to the form page as normal.
Use the click event to load the form into a div using jQuery.get().
I am not sure whether this will work with a form.
Get a copy of "Drupal 6 Javascript and jQuery" if you haven't got one. It won't give you all the answers but it will be a lot of help. Even if you are a js / jQuery expert it will help fill the gaps in how they interface to Drupal.
Thanks again I am terrible at
Thanks again
I am terrible at Javascript and don't even know what Jquery is! But keen to learn.
Will get a copy of that book for sure.
Thanks again
Best wishes,
Andrew
Let me know if you need help
Let me know if you need help
Hi again - I know this isn't
Hi again -
I know this isn't the right place to post this, but have just tried sending you an email via your website - http://www.berksoft.co.uk but got an error message when sending.
Would you mind if I emailed you directly? Have a question for you.
Thanks,
Andrew
andrew@flair.ltd.uk
The contact form on the web
The contact form on the web site probably isn't working again because the host messes around with the mail settings. You can contact via the contact form or tony.walton@berksoft.co.uk
Regards,
Tony Walton
Thanks a lot , works very
Thanks a lot , works very nice
The code above works for D7 too
Hey, many thanks, the solution you posted works for me too, and it does what i expected for Drupal 7 too. I had a similar scenario.
So thanks again.
Alberto
Using alternate displays with different roles/permissions
Hi,
I was thinking the same effect could be achieved without writing any PHP (I haven't tested views' translation for headers and footers but I guess they should work).
Note that I'm new to Drupal so the following may not be good practice.
For my purpose, I simply cloned the display which doesn't have the option to add new content and would then change the new display's permissions (to "create new page", for example) or use roles (e.g. authenticated user, admin etc). In the header I can add "Global:Unfiltered text" to the header and type something similar to:
Create New Page
I would keep the anonymous role and empty header in the original display.
While both displays would have the same path I would use "reorder displays" in the top right menu to make the new authenticated display be on top (i.e. have priority). Views shouldn't have a problem with this.
I have added the code below
I have added the code below to my VIEW in the header using Global:PHP. I also have 'Display even if view has no result' checked, because if I don't the link does not show up. So with the current setup it works and the button shows up. HOWEVER, I am also using Node Limit so that each user can only create a Member Portfolio once. So on the View if the user clicks the 'Add new page' button and they haven't created a page yet then it takes them to the correct page so they can. The problem I am having is if the user has created a Member Portfolio page already and clicks the button it gives them an error: "You are not authorized to access this page."
So the question is how can I modify this output where it does not show up if they have already created a Member Portfolio? I rather them not see the button than get an error.
What about the "plus sign" icon?
This might be taboo but creates the plus sign icon like on the content page:
Is this still the best way for Drupal 8?
Is doing a PHP code snippet still the best way to put an Add/New/Create button in a view header in Drupal 8?
In any case, here are three separate ways of putting an add/new/create button at the top of a view in Drupal 8:
=-=-=-=
[1] Install the PHP filter module. Then follow SweeneyTodd's instructions above but use the following PHP code snippet instead of his. This example is for creating a new node of type "page". You can replace the word "page" with the backend name of your entity type if you want to want to use this for another entity type.
[2] Install the PHP filter module. Then follow SweeneyTodd's instructions above but use the following PHP code snippet instead of his and then fix this PHP so it will work. (It looks right to me but I couldn't get it to work.) This example is for creating a new node of type "page". You can replace the word "page" with the backend name of your entity type if you want to want to use this for another entity type.
[3] Use the view plugin I have created. See View area Button
=-=-=-=
If the new node should be the child of another entity and that entity is being displayed on the page, then you should be able to use the Prepopulate module to relate the new child node to its parent node.
(It's kind of surprising that such basic functionality as a button to create a new node would require any of this.)
Thanks for doing this
Thanks for your feedback regarding how to do this in 8. I was wondering whether you plan to graduate the sandbox project to a module proper? Not sure what the implications of using a sandbox module on a production site are.
Would rather use a module proper instead of the PHP Filter module with that code, as I kind of want to keep PHP out of the GUI.
+1, I am also facing the very same need
I would very much appreciate a non-sandbox module.
How do you return to the view after the edit/delete/create
What would be the best way to change the content type form so that when completed , would direct you back to the view?
hook_form_alter? Not 100% sure how to use that , and if I did, would have to create/install a dummy module to load that function correct?
Or is there some other simpler way?
No replies on this one? I
No replies on this one? I would love to get an answer to this.
This worked fine for me - use current_path
I tweaked the code above to include a destination parameter on the link:
@gdesmarais - "The string
@gdesmarais - "The string views:calendar:default:footer:views:area:content for textgroup views is not allowed for translation because of its text format."
also only admin can see this code. when user with right permissions see a view there is no link.
Drupal beginer
I have add this code to
I have add this code to template.tpl.php file and it works only for admin, as above. User don't see this link.