class EntityFinder in UI Patterns 8
Find a content entity in a render array if keyed by '#object'.
Hierarchy
- class \Drupal\ui_patterns_field_group\Utility\EntityFinder
Expanded class hierarchy of EntityFinder
2 files declare their use of EntityFinder
- EntityFinderTest.php in modules/
ui_patterns_field_group/ tests/ src/ Unit/ EntityFinderTest.php - PatternFormatter.php in modules/
ui_patterns_field_group/ src/ Plugin/ field_group/ FieldGroupFormatter/ PatternFormatter.php
File
- modules/
ui_patterns_field_group/ src/ Utility/ EntityFinder.php, line 10
Namespace
Drupal\ui_patterns_field_group\UtilityView source
class EntityFinder {
/**
* Find content entity object if any.
*
* @param array $fields
* Fields array.
*
* @return \Drupal\Core\Entity\ContentEntityBase|null
* Entity object or NULL if none found.
*/
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;
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityFinder:: |
public | function | Find content entity object if any. |