You are here

function feeds_para_mapper_create_paragraph in Feeds Paragraphs 7

Creates and attaches a Paragraphs entity to another entity.

Parameters

string $bundle: The target bundle.

string $field: The host field.

object $host_entity: The host entity.

string $host_type: The host type.

Return value

\ParagraphsItemEntity The created Paragraphs entity

2 calls to feeds_para_mapper_create_paragraph()
feeds_para_mapper_create_parents in ./feeds_para_mapper.module
Creates a paragraph entity and its parents.
feeds_para_mapper_duplicate_existing in ./feeds_para_mapper.module
Duplicates an existing paragraph entity.

File

./feeds_para_mapper.module, line 1089
Allows feeds to import content to Paragraphs' fields.

Code

function feeds_para_mapper_create_paragraph($bundle, $field, $host_entity, $host_type = "paragraphs_item") {

  // todo: Test appending to db data:
  $created = entity_create('paragraphs_item', array(
    'bundle' => $bundle,
    'field_name' => $field,
  ));
  if ($created instanceof ParagraphsItemEntity) {
    try {
      $created
        ->setHostEntity($host_type, $host_entity);
    } catch (Exception $exception) {
      $m = t("Could't set host entity");
      drupal_set_message($m, 'error');
      drupal_set_message(t('%err', array(
        '%err' => $exception,
      )), 'error');
    }
  }
  return $created;
}