function devel_generate_entity_insert

Same name in other branches
  1. 8.x-1.x devel_generate/devel_generate.module \devel_generate_entity_insert()

Implements hook_entity_insert().

File

devel_generate/devel_generate.module, line 68

Code

function devel_generate_entity_insert(EntityInterface $entity) {
    // Adding url alias is now moved into develGenerateContentAddNode().
    // @todo Can more of this processing moved there too?
    if ($entity->getEntityTypeId() != 'node' || !isset($entity->devel_generate)) {
        return;
    }
    
    /** @var \Drupal\node\NodeInterface $entity */
    $results = $entity->devel_generate;
    if (!empty($results['max_comments'])) {
        foreach ($entity->getFieldDefinitions() as $field_name => $field_definition) {
            if ($field_definition->getType() == 'comment' && $entity->get($field_name)->status == CommentItemInterface::OPEN) {
                // Add comments for each comment field on entity.
                devel_generate_add_comments($entity, $field_definition, $results['users'], $results['max_comments'], $results['title_length']);
            }
        }
    }
    // Add node statistics.
    if (!empty($results['add_statistics']) && \Drupal::moduleHandler()->moduleExists('statistics')) {
        devel_generate_add_statistics($entity);
    }
}