Solution by jasperE3.
We solve
f(f(x)2+f(x)f(y))=f(x)2+f(x)f(y).
Let ∅=S⊆R have the closure property that
a,b∈S⇒a2+ab∈S.
Put
T={a2+ab∣a,b∈S}.
Then all solutions are
f(x)={x,g(x),x∈T,x∈/T,
where g:R∖T→S is arbitrary.
First, such functions work. Since T⊆S, we have f(x)∈S for every x. Hence
f(x)2+f(x)f(y)∈T,
so
f(f(x)2+f(x)f(y))=f(x)2+f(x)f(y).
Conversely, let f be any solution and set
S=f(R).
Then S is nonempty, and if a,b∈S, write a=f(x) and b=f(y). The equation gives
f(a2+ab)=a2+ab,
so a2+ab∈S and S has the required closure property. Moreover, for
T={a2+ab∣a,b∈S},
the same identity shows f(t)=t for all t∈T, while for x∈/T we only need f(x)∈S. This gives exactly the stated family.