I'm using drupal 8.
Lets assume the following. I have created a content type called Foo
. Using the presave hook(hook_entity_presave
), I'm modifying some fields in that content type.
Firstly I want to determine if the entity I'm modifying is a Foo
content type.
I've tried using Drupal\Core\Entity\EntityInterface $entity->getEntityType()
however the return is object(Drupal\Core\Entity\ContentEntityType)
. So basically an object.
Since my knowledge of drupal 8 is not that great(yet) I assumed initially that it would return something more quantifiable like a string or something of the sort. Obviously I was wrong.
Secondly I want to NOT modify some fields if the fields already have a value. Again, I assume a simple isset
or empty
will do the trick. I could be wrong. If there are some other ways to do that, more drupal-like way, I'd be more than happy to understand it better.