src/Form/ChoiceList/ModelChoiceList.php
public function getEntity($key)
    {
        if (\count($this->identifier) > 1) {
            // $key is a collection index
            $entities = $this->getEntities();

            return $entities[$key] ?? null;
        } elseif ($this->entities) {
            return isset($this->entities[$key]) ? $this->entities[$key] : null;
        }

        return $this->modelManager->find($this->class, $key);
    }
public function getEntity($key)
    {
        if (\count($this->identifier) > 1) {
            // $key is a collection index
            $entities = $this->getEntities();

            return $entities[$key] ?? null;
        } elseif ($this->entities) {
            return isset($this->entities[$key]) ? $this->entities[$key] : null;
        }

        return $this->modelManager->find($this->class, $key);
    }
public function getEntity ( $ key ) { if ( \ count ( $ this -> identifier ) > 1 ) { // $key is a collection index $ entities = $ this -> getEntities ( ) ; return $ entities [ $ key ] ?? null ; } elseif ( $ this -> entities ) { return isset ( $ this -> entities [ $ key ] ) ? $ this -> entities [ $ key ] : null ; } return $ this -> modelManager -> find ( $ this -> class , $ key ) ; }
Returns the entity for the given key.

If the underlying entities have composite identifiers, the choices
are initialized. The key is expected to be the index in the choices
array in this case.

If they have single identifiers, they are either fetched from the
internal entity cache (if filled) or loaded from the database.

@param string $key The choice key (for entities with composite
identifiers) or entity ID (for entities with single
identifiers)

@return object The matching entity
Returns the entity for the given key .