3

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

<?php

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 ...
    }
}
3

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, privacy policy and cookie policy

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