public static function ContentProcessorTest::loadFieldFromNode in GatherContent 8.4
Read field from id like "node.mytype.myfiled||paragraph.myptype.mypfield".
1 call to ContentProcessorTest::loadFieldFromNode()
- ContentProcessorTest::assertNodeEqualsGcItem in tests/
src/ Kernel/ ContentProcessorTest.php - Checks whether a node and a GC item contains the same data.
File
- tests/
src/ Kernel/ ContentProcessorTest.php, line 192
Class
- ContentProcessorTest
- Class for testing core node import functionality.
Namespace
Drupal\Tests\gathercontent\KernelCode
public static function loadFieldFromNode(NodeInterface $node, array $ids, $language) {
if (count($ids) == 1) {
throw new \InvalidArgumentException('"$ids" is not a nested id');
}
$currentEntity = $node;
for ($i = 0; $i < count($ids) - 1; $i++) {
$currentFieldName = explode('.', $ids[$i])[2];
$value = $currentEntity
->get($currentFieldName)
->getValue();
$targetField = reset($value);
$currentEntity = Paragraph::load($targetField['target_id']);
}
$lastFieldName = explode('.', end($ids))[2];
$currentEntity = $currentEntity
->getTranslation($language);
return $currentEntity
->toArray()[$lastFieldName];
}