You are here

function devel_generate_entity_insert in Devel 4.x

Same name and namespace in other branches
  1. 8.3 devel_generate/devel_generate.module \devel_generate_entity_insert()
  2. 8 devel_generate/devel_generate.module \devel_generate_entity_insert()
  3. 8.2 devel_generate/devel_generate.module \devel_generate_entity_insert()

Implements hook_entity_insert().

Inserts nodes properly based on generation options.

@todo Can more of this processing move into develGenerateContentAddNode() ? Adding url alias is now moved.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The base node created on submit. Inspects $node->devel_generate.

File

devel_generate/devel_generate.module, line 73

Code

function devel_generate_entity_insert(EntityInterface $entity) {
  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);
  }
}