I have the issue #1923328: Notice: Undefined property: stdClass::$field_tags in linkchecker that I do not understand yet and I need some help about this field issue.

If a new article node is added (via node/add) the field_tags field is completely missing in the $entity. This seems not happen if you edit the node later (node/edit). I get a notice for line $entity->$field['field_name'];, but I think this field_name must always exists in the entity. I cannot find any other example in core that handle or workaround this type of notices.

Code example:

  // Collect the fields from this entity_type and bundle.
  foreach (field_info_instances($entity_type, $bundle_name) as $field_name => $instance) {
    $field = field_info_field($field_name);
    // #1923328: field_name array may be missing in $entity if field is empty.
    $entity_field = $entity->$field['field_name'];

  ...

What's wrong here?

Here is a ling to the full source code: http://drupalcode.org/project/linkchecker.git/blob/refs/heads/7.x-1.x:/l...

Comments

hass’s picture

Issue summary: View changes

a

yched’s picture

the field_tags field is completely missing in the $entity

Where are we in the code flow ? Which hook, step or function ?

[edit: oops, sorry, there's a link in the OP - a bit buried in function calls though. Can you point to the place in the callstack where those are called ?]

hass’s picture

I'm getting the $node object in hook_node_insert(). Than later _linkchecker_parse_fields('node', $node->type, $node, TRUE)) (http://drupalcode.org/project/linkchecker.git/blob/refs/heads/7.x-1.x:/l...) is called and 9 lines later the code snippet from above is in action.

Does this make things clear?

yched’s picture

You're allowed to do a node_save($some_object) with a $some_object that doesn't contain properties for all fields present in the node type, so yes, no guarantee you'll always find $node->$field_name present in the $node object you get.

hass’s picture

Thanks for this details. What is the recommended way to find out the fields that exist in the submit? Is there anything wrong how I access the fields? Are there any API functions or generic conditions that I may missed?

yched’s picture

if (isset($entity->{$field_name})) is fine

hass’s picture

Category: bug » support
Status: Active » Fixed

thx

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

a