public function EntityFieldTest::getContainedStrings

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

1 call to EntityFieldTest::getContainedStrings()
EntityFieldTest::testDataStructureInterfaces in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
Tests working with entity properties based upon data structure and data list interfaces.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php, line 382
Definition of Drupal\Core\Entity\Tests\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);
      }
    }
  }
}