public function EntityFieldTest::getContainedStrings

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

1 call to EntityFieldTest::getContainedStrings()
EntityFieldTest::assertDataStructureInterfaces in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
Executes the data structure interfaces tests for the given entity type.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php, line 508
Definition of Drupal\system\Tests\Entity\EntityFieldTest.

Class

EntityFieldTest
Tests Entity API base functionality.

Namespace

Drupal\system\Tests\Entity

Code

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

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