You are here

public function EntityFieldTest::getContainedStrings in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::getContainedStrings()

Recursive helper for getting all contained strings, i.e. properties of type string.

1 call to EntityFieldTest::getContainedStrings()
EntityFieldTest::doTestDataStructureInterfaces in core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
Executes the data structure interfaces tests for the given entity type.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php, line 596

Class

EntityFieldTest
Tests the Entity Field API.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function getContainedStrings(TypedDataInterface $wrapper, $depth, array &$strings) {
  if ($wrapper instanceof StringInterface) {
    $strings[] = $wrapper
      ->getValue();
  }

  // Recurse until a certain depth is reached if possible.
  if ($depth < 7) {
    if ($wrapper instanceof ListInterface) {
      foreach ($wrapper as $item) {
        $this
          ->getContainedStrings($item, $depth + 1, $strings);
      }
    }
    elseif ($wrapper instanceof ComplexDataInterface) {
      foreach ($wrapper as $property) {
        $this
          ->getContainedStrings($property, $depth + 1, $strings);
      }
    }
  }
}