I have created a content entity type. When I save form, I got id in routing url, like:
entityform/1
entityform/2
But if I directly access some non-existing id like entityform/999
, page dies.
In watchdog, it is showing error,
Error: Call to a member function get() on null in Drupal...
I can not call function get() on the fields of entity, if entity doesn't exists.
$content_type = $entity->get('ctype')->value;
How to apply this check, whether entity actually created or not?
ctype
is the field of an entity. I'm getting this field value from$content_type = $entity->get('ctype')->value;
. But what If I'm fetching the field value of entity that no where exists. Thatswhy it is giving error, 'calling functiojn get() on null', because field doesnt et created if there is no entity. – Sugandh Khanna Jun 23 '16 at 11:26isset()
or is notNULL
, and useget()
only if the condition passes. – Oana Hulpoi Jun 23 '16 at 11:32