Feature: A Preview button that shows you the full page layout, with previewed content.

When creating a node, and you hit the 'Preview' button, just the content is previewed in the current form.

How about research into a contrib module, to allow the Preview button to show the page layout containing previewed content instead of just the content inside the current form.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vosechu’s picture

Status: Needs review » Needs work

I like this idea a lot. Are you thinking a lightbox popup for preview?

Also, needs to conform to the task template.

aufumy’s picture

Task title: Full preview button.

Task description: A full preview button, allows the user to not just preview the node title/body modifications, but a full shot of the page including the blocks on a page, with the content replaced with the previewed content.

Deliverables: A contrib module for drupal 6, depending on modal frame api. Or maybe for drupal 7, mimicking /admin/structure/block/demo/bartik

Resources: http://code.google.com/p/google-highly-open-participation-drupal/wiki/Fu...

Primary contact: I can review, but there are likely better drupal core reviewers.

vosechu’s picture

Awesome, this is going to be great! Do you think this will be doable in a week or is it longer? Can you tag with gci-medium/hard/easy based on your feelings about it?

Also, from your history of contributions it seems like you should actually be the mentor or go a hunt down the core dev that you want to work with. Webchick isn't going to find the right mentor unless we ask her directly (I'm going to do the same in my issues as well).

aufumy’s picture

Issue tags: +gci-medium

Ok, will think about what mentors, I can suss out.

aufumy’s picture

Component: Research » Code
Status: Needs work » Needs review
vosechu’s picture

Cool, +1 from me then. I think this is a great idea and I hope that we can get this!

vosechu’s picture

Status: Needs review » Reviewed & tested by the community
cwgordon7’s picture

Aufumy, you can be listed as the primary mentor, and you can direct your student to other community members as necessary. This should be done as a module for Drupal 7, not for Drupal 6, so it can make use of the administration overlay as a dependency.

Otherwise, this looks great, thanks!

cwgordon7’s picture

Hi aufumy,

Please make an account on the google application site and apply to be a mentor for Drupal, so I can add this task. It needs a mentor listed on the google system. You can apply here: http://socghop.appspot.com/gci/mentor/request/google/gci2010/drupal. Thanks!

Anonymous’s picture

Hi aufumy,

Could you also estimate the time, in hours, that it would take a student to complete this task once it is claimed? This estimate is required to input the task into the google system.

Thanks!

dawehner’s picture

Update status, rtbc means it's ready to be pushed to melange :)

dawehner’s picture

Status: Reviewed & tested by the community » Active

http://www.google-melange.com/gci/task/show/google/gci2010/drupal/t12904...

This issue waits for a official mentor
Sent a message to aufumy.

vosechu’s picture

Issue tags: +needs mentor

adding needs-mentor tag

webchick’s picture

Project: Google Code-in » Drupal core
Version: » 8.x-dev
Component: Code » node system
bluman’s picture

Assigned: Unassigned » bluman

I took the task from GCI and I think I almost solved it. My idea is to add the node using a special flag in the database and allow the administrator to edit/modify and eventually save it and publish to the public. This would be like saving it without publishing, but in a easier way. At the moment I have implemented the button and the saving of the node with that special flag allowing the save and editing and have to implement a deletion of the previews older than one hour and also to somehow memorize the published/unpublished status as the preview flag overwrites it in the database. I think that to solve the second problem I'll implement a new column, but the sketch is done. Please tell me what you think about the idea. Also soon I will post the patch so you can all test it.

Thanks,
Paul Herman

bluman’s picture

FileSize
11.83 KB

Here is the first upload. I think it's ready, please test it.

vosechu’s picture

I'm not close enough to core to know any better but is it possible to do this in a contrib module? I really want to see this in 7 but core patches are going to take forever to get in since we're in code freeze until 7 is out (and then features won't get wrapped in until D8 so that may be another year).

So is this even possible in contrib?

vosechu’s picture

PS. While I'm not really a great mentor for this I'm going to try to steward it a little bit so that you can get credit. I'll be asking for reviews in IRC but I would encourage you to talk to people in #drupal-contribute about this task since there's a lot of great developers in there.

agentrickard’s picture

The problem with this approach is that it introduces core changes to node module too late in the D7 release cycle. It also returns some old logic that we deliberately removed in D7.

Specifically this line change:

-  elseif (in_array(NODE_ACCESS_ALLOW, $access, TRUE)) {
+  elseif (in_array(NODE_ACCESS_ALLOW, $access, TRUE) && $node->status == 1) {

And the task itself specifically asks for a contrib module (not a core change) for precisely this reason.

You may be on to something with the pre-save trick, but then what if the node creation is abandoned? The loop through and delete on cron is a bit dicey. Really, what I think we need is a form_alter that intercepts the behavior of the 'Preview' button:

  $form['actions']['preview'] = array(
    '#access' => variable_get('node_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_DISABLED,
    '#type' => 'submit',
    '#value' => t('Preview'),
    '#weight' => 10,
    '#submit' => array('node_form_build_preview'),
  );

Changing the #submit callback should allow the generation of a popup preview or similar inside a custom module.

cwgordon7’s picture

Project: Drupal core » Google Code-in
Version: 8.x-dev »
Component: node system » Code
Issue tags: -gci-medium-hard +gci-medium

Sorry, bluman, I think agentrickard is right, this needs to be a contributed module. In fact, the issue specifically states that the deliverable is a contributed module. However, some of the code you've written will still be useful. Maybe you can turn this into a contributed module for Drupal 7?

Thanks!
Charlie

bluman’s picture

I had to modify the access function, as I even think I have found a bug in it, it allows you to view unpublished nodes without being an admin or sth(not even logged in). About the module creation, could you point me to some tutorials as I'm new to drupal.

bluman’s picture

Status: Needs work » Active
FileSize
1.94 KB

Here is the first beta of the module. Please test it and submit me some feedback.

agentrickard’s picture

Will do. I actually have a project that is perfect for testing this.

@cwgordon7 you want to add me as mentor for this one?

agentrickard’s picture

Status: Active » Needs work

Wow. This code needs a refactor, given that there are curse words on line 4. Totally inappropriate and grounds for expulsion from GCI.

I'd still like to see this accomplished without saving the node to the db, is that even possible? Did you try?

There are also no Doxygen comments and some irregular use of code style.

See http://drupal.org/coding-standards

Note also that the 'preview' namespace is taken in Drupal CVS. http://drupalcode.org/viewvc/drupal/contributions/modules/preview/

bluman’s picture

Status: Active » Needs work

I'm sorry for that words. I was really angry about hiding the menu. Sorry. Also about the method without saving, I've tried to think about it, but haven't got any ideas. Could you delete the atachment temporarely to fix that line 4? Again sorry.

bluman’s picture

FileSize
2.55 KB

Here is the version without that words. Sorry about them.

agentrickard’s picture

Well, what does the normal "preview" action do?

bluman’s picture

It shows the content of the node in the current editing form without allowing to view the full node.

cwgordon7’s picture

Agentrickard, you can be the mentor for this, that's great actually. Bluman, you can contact agentrickard with any questions.

I believe it's impossible to do this without saving the node in the database, because there are contributed modules that may read directly from the database when deciding, say, which blocks to display on a page. The solution is to add a "preview" flag to the database that toggles something in node access that only allows the original author to see it.

bluman’s picture

FileSize
2.52 KB

I've reviewed the code and I think that this version should be good. Please review it and give me feedback. Thanks for support cwgordon7 and agentrickard!

agentrickard’s picture

Here's my problem with saving nodes in the database:

-- If you do that, you're really just saving an "unpublished" node. D7 already has a feature that allows authors to view their own unpublished nodes. So this approach doesn't add any benefit there. The menu handling is redundant, too, since unpublished nodes are not shown in the menu,

-- If you have to handle this as "unpublished" and the user has revisioning turned on, it will create a new revision on every node save, which is not the functionality that a "full preview" would try to accomplish.

-- If you have to set the node to "unpublished" to view the preview, then what happens when you want to preview changes to existing nodes? Then you would have to alter the active version id (vid) for the node, which can be very ugly to handle.

The normal chain in Drupal core is:

-- Press "preview" button.
-- Fire node_form_build_preview.
-- Fire node_form_submit_build_node.
-- Fire and theme node_preview.

What we might want to do is handle the preview form a little better by invoking the site theme instead of the admin theme and hiding the rest of the node form if $form_state['node_preview'] is not empty. Instead, we would present a 'Save' and 'Edit' button on the preview page.

If we can make that work, then we don't need any of the menu handling, the cron or the node access functions, all of which introduce edge cases that will be very hard to debug.

I'm going to test the existing code and make additional comments.

agentrickard’s picture

In this version of the code, the node is hidden at /node/NID but visible on /node IFF published and promoted (which is the default setting for new nodes). So that's not what we want.

We should also be able to provide Full Preview on existing nodes.

agentrickard’s picture

FileSize
2.69 KB

Here's stub code that outlines the non-save approach, but leaves plenty of tasks TODO.

bluman’s picture

FileSize
2.17 KB

Here is the version that is done through cache. Please test it and send me some feedback. The only "to do" is to make the editing in overlay.

agentrickard’s picture

Status: Needs work » Needs review
Issue tags: -needs mentor

An update of where we stand on this task, which was not clearly defined at the outset.

-- @bluman and I spent about an hour on IRC yesterday, reviewing possible approaches. We found three:

a) Save the node and display preview to the author only. This approach was rejected for security reasons, as described in #32 and #33. Saving the node is not the preferred method for generating a preview.

b) Use $form_state to display the node preview instead of the form, and provide SAVE and EDIT buttons to either save the changes or return to editing. This was promising, but we had some difficulty making the $form_state behave as expected; we also couldn't alter the page theme properly. We may return to this approach, but likely after GCI.

c) Save the temporary $node object created by the form to either a SESSION or CACHE variable. Then use a menu callback to generate a page that previews this copy of the $node object. @bluman has gone this route, using a callback to generate the preview from a copy of the node that is cached when the node is "previewed".

This (c) approach is what is under review now.

Goals:

-- New and existing nodes should be editable. Those edits should appear when the Full Preview button is submitted.
-- The Full Preview should open in a new window, a lightbox, or by loading a new page that does not disrupt the current state of the editing form.
-- The Full Preview should display the entire node page -- including the site theme, header navigation, sidebars and blocks -- so the editor can see the context of the changes.
-- From the Full Preview page, the editor should be able to go back to the edit screen. If possible -- but not a hard requirement -- the editor should be able to save the edits from the preview screen.

bluman’s picture

FileSize
2.18 KB

Here should be the first usable build. Please review it. Thanks!

agentrickard’s picture

As I was afraid, using pnode/ for editing breaks the image uploader when editing an Article. The preview doesn't work for new images, either.

Notice: Undefined index: uri in theme_image_formatter() (line 533 of /Applications/MAMP/htdocs/drupal-cvs/modules/image/image.field.inc).

Still, we can work through that. I think we can mark this task as a success.

Opinions?

bluman’s picture

FileSize
2.62 KB

I've added the comments and the mentor said that it is good.

agentrickard’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
4.01 KB

I made a few adjustments just for style and standards. A summary:

-- removed fullpreview.install, since that is unused.
-- cleaed up .info file for standards
-- moved drupal hooks to top of file, as best practice.
-- ensured proper spacing of Doxygen comments.

There is still some polish for this module, but as far as a research project, it's great. Uncovers many of the issues facing this process, and provides a nice basis to work from.

Marking as approved in GCI.

Les Lim’s picture

I just committed what is essentially a D6 implementation of approach (c) above a few days ago. I wish I'd come across this beforehand.

http://drupal.org/project/pagepreview

Combine efforts?

agentrickard’s picture

Definitely. Note that this was aiming at D7, so there wasn't quite a duplication of work.

The iframe trick in your code is a sneaky alternative to one of the problems we ran into.

saadshaukat’s picture

Hi,

This module is superb. I have installed this module and it works fine for 'create content' or edit content forms. But I want to add a preview button to my custom form.

I have tried adding a preview button of a submit type and then calling pagepreview_node_form_build_preview when submitted using preview button.

It was first giving me an error that function node_form_submit_build_node is undefined but then I added this code module_load_include('inc', 'node', 'node.pages') to fix this issue. Now, form is submitted but it do not show the preview, instead it shows the form is saved message.

Can any one please direct me to the right direction to how I can use preview feature on my custom forms.

Many Thanks

agentrickard’s picture

@saadshaukat

This was a student project, and I don't know if anyone is actively tracking it right now. If you are using Drupal 6, you might try http://drupal.org/project/pagepreview instead.

saadshaukat’s picture

http://drupal.org/project/pagepreview is same as this project.

agentrickard’s picture

Status: Reviewed & tested by the community » Closed (fixed)

File support issues over there, please. This is the student issue queue unrelated to the stable release.

knaffles’s picture