4

I use Drupal 8 and I have a content type which has a field that references another content type as a entity reference field. I use a rest endpoint to create the node and the referenced node which works fine.

I also have the workbench module installed so I can change the moderation state of the nodes.

The problem is that when I change the moderation state from draft to review I get the error This entity (node: {ID}) cannot be referenced.

Why am I getting this?

8 Answers 8

3

The view_unpublished "module allows you to grant access for specific user roles to view unpublished nodes of a specific type. Access control is quite granular in this regard."

composer require drupal/view_unpublished
drush en -y view_unpublished

At /admin/people/permissions set permissions as required:

Permissions page showing content type access for certain roles

Finally, at /en/admin/reports/status/rebuild rebuild the permissions, which may take some time:

Progress bar showing rebuilding of permissions

1

The issue was that the field was used to reference unpublished nodes and kept throwing the error. I updated the field to allow unpublished nodes too. It worked.

6
  • 2
    Where exactly did you update the field to allow unpublished content as well?
    – Hugo
    Commented Aug 30, 2017 at 10:38
  • In the drupal menu select structure and then content type. Select the content type in question and about half way down he page there is a option selection box. In that box you select unpublished
    – harnamc
    Commented Aug 30, 2017 at 12:02
  • I must be missing it, here's what I see at /admin/structure/types/manage/article: i.sstatic.net/3qCgH.png Please could include a screenshot?
    – Hugo
    Commented Aug 30, 2017 at 12:34
  • 1
    I only see "Default" and "Views: Filter by an entity reference view": i.sstatic.net/zBzPm.png I've found another way, which I'll post as an answer.
    – Hugo
    Commented Aug 31, 2017 at 6:33
  • 1
    Having just been in this situation, I'll second @Hugo 's observation that I also didn't see what Harnamc suggests looking for. I'm wondering if Harnamc has enabled a module, and now is taking this functionality extension for granted? Regardless, this suggestion isn't valid on our D8.3 site.
    – Screenack
    Commented Sep 6, 2017 at 19:52
1

We can use this module entity_reference_unpublished. Or add "bypass node access" permission.

!!! This is very powerful permission that you may not want to give to your editors.

1

Check that the view does not have a filter for 'Content: Published (=Yes)'.

The validator uses an entity_reference view to get a list of valid entity ids. If the entity selected (e.g. from entity_browser view) is not in the list of valid ids, then this error will be displayed.

Ensure that both views have the same criteria.

If you are working in workflow, the default 'Published' may not be the filter criteria that you want.

enter image description here

0

The views_unpublished module (from this answer) has an ominous bug for multilingual sites and translations with different published status.

An alternative is to use a patch from 'Move permission "view any unpublished content" from content moderation to core: this is something which is currently targeting Drupal Core 8.5. At the time of writing, I've used this patch in Drupal 8.3.7.

0

I was getting this when the Manage fields > Reference Type wasn't set. There are 2 kinds of reference: Reference method and Content type and it is possible to not select anything here - selecting the correct content type solved the issue for me.

0

I had received the same error during form submission of a content type.

I was using an entity reference field with Ajax that is set to display values of two other taxonomy reference fields in the same content type. The field could only show terms selected in the other two fields.

On form submission I was getting this error. I found that the root cause of the problem was that the ajax field was not set to reference one of the vocabulary in the other field.

I proceeded to edit the field settings and enable the vocabulary in the checkboxes. The error was resolved after that.

0

Many of the other answers here require installing new modules and making configuration changes. If you're comfortable with adding patches to your site, see the patches at the bottom of this issue: https://www.drupal.org/project/drupal/issues/2845144

In theory this is ready to be committed to Drupal Core as of May 2020. However, my guess is that there will be debates about whether this breaks backwards compatibility, and ultimately won't be committed until Drupal 10.

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.