function EntityFieldTest::getContainedStrings

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::getContainedStrings()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::getContainedStrings()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::getContainedStrings()

Gets all contained strings recursively.

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 598

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);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.