0

I have an entity reference view setup that currently pre-populates a content authors user name into the content form. This field has to stay the same no matter which user edits it in the future.

It works however it only works for editing content, nothing is pre-populated when creating new content with the form. I've tried adding the current user ID to the form but that will only work for creating new content and it is overridden each time the node is edited.

I can figure out how to do both the things I need but they refuse to play together. It seems like it's has to be one or the other. But there must be a way!

How would I filter the view to show the content author and the current logged(or original author) in user for use on both the edit and create new content pages? Here is a screenshot of my view:Screenshot of my view And the contextual filter settings: enter image description here

5
  • 1
    Could you perhaps upload a screenshot of the view so we can see what you already have? Jun 8, 2017 at 17:43
  • Just added a screenshot :). I originally started with the "create" form pre-populating with the current user ID but it would be overridden each time the node was edited by a different user. The view as it is works on edit pages, but only on edit pages. It's confusing why they won't work together.
    – Krypton
    Jun 8, 2017 at 17:48
  • The only thing I can think of is that I'm using the wrong filter. Is there a filter that will always show the content author even before the content has been created?
    – Krypton
    Jun 8, 2017 at 18:09
  • I was wondering why you'd need this value in the first place... Can't you just obtain the uid from the first revision? (If you enable revisions.) But that depends on where you want to display the value. It would at least always show the correct user. Jun 8, 2017 at 19:33
  • The filter/view is for the current author of content so a field can grab some custom data from their profile. Using the revisions might work but how would that prepopulate the form when creating new content and there aren't any revisions? I would have thought something like this would be standard :(
    – Krypton
    Jun 8, 2017 at 20:23

1 Answer 1

1

The problem is (as your comment indicated) the user id from route. That uses the node id, or user id from the url. On an edit page that is node/123/edit, so it can load the node and obtain the user. For the create page node/create, there is no such id.

Can't you use the User ID from logged in user filter instead? That should work.

5
  • 1
    Oh, read your post again and you already tried that... Jun 8, 2017 at 18:15
  • The User ID from logged in user filter is what I originally had but it won't allow the form to be edited without that part being updated to the last editing user. It's not essential but I'd like for others to be able to edit it without it updating. The form is for the forum module and it's kind of limiting if "moderators" can't edit the content without this form staying as the original authors user ID. Is what I'm trying to accomplish just not do-able? Thanks for the suggestion. If I can't find a way I will be going back to what you've said :)
    – Krypton
    Jun 8, 2017 at 18:19
  • LOL, Commented without seeing your comment :P
    – Krypton
    Jun 8, 2017 at 18:19
  • 1
    NP, I can't think of any other way this fast either... Jun 8, 2017 at 18:22
  • It's got me stumped too. Right now the field is a select box. I think if I changed it to a text box it 'might' be possible to accomplish what I need with this module: drupal.org/project/field_token_value then just set the default for the field as the current user ID token. Would this work without overriding the field each time it's edited? It's too bad that the lasted dev build doesn't work yet :(
    – Krypton
    Jun 8, 2017 at 18:36

Your Answer

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

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