You are here

class EntityFinder in UI Patterns 8

Find a content entity in a render array if keyed by '#object'.

Hierarchy

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\Utility
View 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

Namesort descending Modifiers Type Description Overrides
EntityFinder::findEntityFromFields public function Find content entity object if any.