You are here

protected function FeedsParaMapperWebTestCase::getValues in Feeds Paragraphs 7

Get the paragraph field values.

Parameters

\ParagraphsItemEntity $paragraph: The paragraph entity.

string $target: The target field inside the paragraph entity.

array $values: The previously collected values to append to.

Return value

array array of the values.

2 calls to FeedsParaMapperWebTestCase::getValues()
FeedsParaMapperNestedImportTestCase::testNestedImport in tests/importing.test
Test importing nodes with nested paragraphs fields.
FeedsParaMapperWebTestCase::multiImport in tests/FeedsParaMapperWebTestCase.test
Tests Multi-valued fields importing.

File

tests/FeedsParaMapperWebTestCase.test, line 518
Common functionality for all Paragraphs Mapper tests.

Class

FeedsParaMapperWebTestCase
Test basic functionality via DrupalWebTestCase.

Code

protected function getValues(\ParagraphsItemEntity $paragraph, $target, array $values = array()) {
  $target_info = field_info_field($target);
  $node = node_load(1, NULL, TRUE);
  $lang = $node->language;
  if (isset($paragraph->{$target})) {
    if ($target_info['type'] === 'paragraphs' && isset($paragraph->{$target}[$lang])) {
      foreach ($paragraph->{$target}[$lang] as $item) {
        if (isset($item['value'])) {
          $id = array(
            $item['value'],
          );
          $entity = entity_load('paragraphs_item', $id, array(), TRUE);
          $values[] = reset($entity);
        }
      }
    }
    else {
      if (isset($paragraph->{$target}[$lang])) {
        foreach ($paragraph->{$target}[$lang] as $item) {
          if ($target_info['type'] === 'text') {
            $values[] = $item['value'];
          }
          else {
            $values[] = $item;
          }
        }
      }
    }
  }
  else {
    $keys = get_object_vars($paragraph);
    foreach ($keys as $key) {
      if (is_array($key) && isset($key[$lang]) && is_array($key[$lang])) {
        foreach ($key[$lang] as $item) {
          $item_id = (int) $item['value'];
          if ($item_id) {
            $en = entity_load('paragraphs_item', array(
              $item_id,
            ), array(), TRUE);
            $en = reset($en);
            if ($en) {
              $values = $this
                ->getValues($en, $target, $values);
            }
          }
        }
      }
    }
  }
  return $values;
}