I have used both the dev and stable version of Entity Reference and this notice appears:

Notice: Trying to get property of non-object in entity_metadata_no_hook_node_access() (line 609 of C:\wamp\www\osdb\sites\all\modules\contrib\entity\modules\callbacks.inc).
Notice: Trying to get property of non-object in entity_metadata_no_hook_node_access() (line 610 of C:\wamp\www\osdb\sites\all\modules\contrib\entity\modules\callbacks.inc).
Notice: Trying to get property of non-object in entity_metadata_no_hook_node_access() (line 610 of C:\wamp\www\osdb\sites\all\modules\contrib\entity\modules\callbacks.inc).
Notice: Trying to get property of non-object in entity_metadata_no_hook_node_access() (line 609 of C:\wamp\www\osdb\sites\all\modules\contrib\entity\modules\callbacks.inc).
Notice: Trying to get property of non-object in entity_metadata_no_hook_node_access() (line 610 of C:\wamp\www\osdb\sites\all\modules\contrib\entity\modules\callbacks.inc).
Notice: Trying to get property of non-object in entity_metadata_no_hook_node_access() (line 610 of C:\wamp\www\osdb\sites\all\modules\contrib\entity\modules\callbacks.inc).

The entity_access() function takes as its third parameter an $entity object while the reference module is passing the bundle name instead of an object.

entity_access($op, $entity_type, $entity = NULL, $account = NULL)

The references_dialog_entityreference_link_helper() function calls entity_access without passing the full $entity.

if (entity_access('create', $entity_type, $entity_type == 'node' ? $bundle : NULL) &&

I'm not sure which module is responsible for this problem.

Comments

Adam S’s picture

This is probably an Entity API as node_access() requires the $node parameter to be either a node or in the case of node create a string of the bundle or node type name.

Adam S’s picture

Status: Active » Closed (fixed)

I patched the Entity API at http://drupal.org/node/1780646

mile23’s picture

Title: Using the latest dev (2012-Sep-07) version of Entity API a PHP Notice is created » Entity Reference incorrectly calls entity_access()
Priority: Normal » Major
Status: Closed (fixed) » Needs work

More work has been done on #1780646: entity_access() fails to check node type specific create access and the determination from Fago is: You have to pass in an entity, even if it's one you create as a prototype for the operation.

Bumped to major because this is a bit of a blocker for that other issue: https://drupal.org/node/1780646#comment-7750019

wodenx’s picture

Project: Entity reference » References dialog

The original issue belongs in the references_dialog project.

b-prod’s picture

Status: Needs work » Closed (fixed)

Fixed in the DEV version:

switch ($entity_type) {
    case 'node':
      $access = node_access('create', $bundle);
      break;

    default:
      $access = entity_access('create', $entity_type);
      break;
  }
b-prod’s picture

For those who want a patch against 7.x awaiting the next release.

JvE’s picture

entity_access() doesn't provide a generic bundle create op access check.

This should do it:

  if (!empty($info['entity keys']['bundle'])) {
    $entity= entity_create($entity_type, array($info['entity keys']['bundle'] => $bundle));
  }
  else {
    $entity= entity_create($entity_type, array());
  }
  $access = entity_access('create', $entity_type, $entity);
Yaazkal’s picture

Hi, I was getting this error message when trying to create a node that uses References Dialog (this message is not showed, but is in the drupal log):

EntityMalformedException: Permission to create a node was requested but no node type was given. in entity_metadata_no_hook_node_access() (line 672 of /sites/all/modules/entity/modules/callbacks.inc).

Code on comment #6 fixed it, thanks.

Could be a good option to release other alpha or even beta version including this, because it can prevent many users to have this error.

Regards

hansfn’s picture

FYI: The fixed is included in the new 7.x-1.0-beta1 release, but it's forgotten in the release notes.

nicxvan’s picture

Status: Closed (fixed) » Needs work

I am still receiving this error. I am on beta-1: The following error is posted in my logs.
EntityMalformedException: Permission to create a node was requested but no node type was given. in entity_metadata_no_hook_node_access() (line 678 of /sites/all/modules/entity/modules/callbacks.inc).

nicxvan’s picture

Some notes so I can make a patch later if my reasoning is sound I went through a couple iterations. I need to compare against a clean version and create a patch, but this currently allows for updating and creating nodes with entity reference.

I will post a patch shortly.

94: // Should likely be node_access since it's node_load and can only be nodes
if (node_access('update', $node)) {

119: //
if (node_access('create', $node_type->type)) {

208:
if (entity_access('update', $entity->type, $entity)) {

280: // entity access can check based on the kind of entity, no need to have separate node logic I think
$access = entity_access('create', $bundle);

nicxvan’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB

This is ready to be reviewed and tested. I can now visit new pages with reference dialogs and existing pages.

Status: Needs review » Needs work
JvE’s picture

Status: Needs work » Closed (fixed)

Looks like you're confusing node types and entity types.
Examples of entity types: https://www.drupal.org/node/1261744
- node
- user
- comment
- taxonomy_term

Examples of node types: https://www.drupal.org/node/21947
- article
- basic page
- book page
- forum topic
- poll

About your patch:

  1. +++ b/sites/all/modules/references_dialog/references_dialog.dialog_widgets.inc
    @@ -205,7 +205,7 @@ function references_dialog_entityreference_edit_link($element, $widget_settings,
    -      if (entity_access('update', $entity_type, $entity)) {
    +      if (entity_access('update', $entity->type, $entity)) {
    

    This is wrong. entity_access expects an entity type here (node, user, taxonomy_term, etc.) not a node-type.

  2. +++ b/sites/all/modules/references_dialog/references_dialog.dialog_widgets.inc
    @@ -274,10 +274,10 @@ function references_dialog_entityreference_link_helper($entity_type, $bundle = N
    -  // entity_access() doesn't provide a generic bundle create op access check.
    +  //entity_access() doesn't provide a generic bundle create op access check.
    

    Space should not be removed.

  3. +++ b/sites/all/modules/references_dialog/references_dialog.dialog_widgets.inc
    @@ -274,10 +274,10 @@ function references_dialog_entityreference_link_helper($entity_type, $bundle = N
    -      $access = node_access('create', $bundle);
    +      $access = entity_access('create', $bundle);
    

    Again, entity_access expects the entity type (node, user, taxonomy_term, etc.) and not the bundle (node type for nodes).

The only reason I can think of why this patch appears to help you is that you're running a pre-1.3 release of the Entity API module.

If you do get that error with the latest version of Entity, Entityreference and References dialog, I suggest you apply the patch from https://www.drupal.org/node/1780646?page=1#comment-8350335 to get more debug logging.

nicxvan’s picture

Thanks for the insight, I am running entity 1.5 so that isn't the issue. I will try applying that patch and see if it exposes more information.

1. I do know the difference between node types and entity types, but I thought the entity object had a type field.
2. That was a mistake.
3. I may have misread how it works. I'll take your word for it though and try applying the patch you posted to gather more info. As you can see I'm fairly new at some of this.

gints.erglis’s picture

Here's a different approach - passed entity is empty so it fails entity type check. I'm checking the entity before calling entity access function instead.