public function EntityFinder::findEntityFromFields in UI Patterns 8
Find content entity object if any.
Parameters
array $fields: Fields array.
Return value
\Drupal\Core\Entity\ContentEntityBase|null Entity object or NULL if none found.
File
- modules/
ui_patterns_field_group/ src/ Utility/ EntityFinder.php, line 21
Class
- EntityFinder
- Find a content entity in a render array if keyed by '#object'.
Namespace
Drupal\ui_patterns_field_group\UtilityCode
public function findEntityFromFields(array $fields) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($fields), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $key => $value) {
if ($key === '#object' && $value instanceof ContentEntityBase) {
return $value;
}
}
}