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
Comment #0.0
hass CreditAttribution: hass commenteda
Comment #1
yched CreditAttribution: yched commentedWhere 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 ?]
Comment #2
hass CreditAttribution: hass commentedI'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?
Comment #3
yched CreditAttribution: yched commentedYou'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.
Comment #4
hass CreditAttribution: hass commentedThanks 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?
Comment #5
yched CreditAttribution: yched commentedif (isset($entity->{$field_name})) is fine
Comment #6
hass CreditAttribution: hass commentedthx
Comment #7.0
(not verified) CreditAttribution: commenteda