Recursive helper for getting all contained strings, i.e. properties of type string.
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);
}
}
}
}