trying to find if node is bundle article (node bundle = content type) before executing the rest of the statements in the following example

I can test if the entity is node but I can't figure out how to test if content type is article


use \Drupal\Core\Entity\EntityInterface;

function MODULE_NAME_entity_presave(EntityInterface $entity){

    //if content type is article 
    if ($entity->getEntityType()->id() == 'node') {  
        //do wonderful stuff ...

1 Answer 1


I did manage to find it after all $entity->bundle() it was pretty easy ...

 if ($entity->getEntityType()->id() == 'node' && $entity->bundle() == 'article') { 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.