Problem/Motivation

Currently Drupal\render_cache_entity\RenderCache\ControllerEntityController::render() and the subsequent code "assume" that the $build array is keyed by the entity id.
Unfortunately this isn't true if the controller extends \EntityAPIControllerExportable from the Entity API module.
This leads to fatal errors like:

Notice: Undefined index: xxxxxxxxxxxxx in Drupal\render_cache\Cache\RenderCacheBackendAdapter->setMultiple() (line 195 of render_cache\src\Cache\RenderCacheBackendAdapter.php).
Recoverable fatal error: Argument 2 passed to Drupal\render_cache\Cache\RenderCacheBackendAdapter::set() must be of the type array, null given, called in render_cache\src\Cache\RenderCacheBackendAdapter.php on line 195 and defined in Drupal\render_cache\Cache\RenderCacheBackendAdapter->set() (line 110 of render_cache\src\Cache\RenderCacheBackendAdapter.php).

Proposed resolution

For now we should check if the entity controller is a \EntityAPIControllerExportable and change the keys to ids again.
This isn't the most generic approach since it doesn't get rid of the assumption that we'll always have an array keyed by entity ids - but for now the most stable approach I could come up with.

Another approach would be to use $entities as source for the keys using array_combine() to create $build - but this would introduce the assumption that the order and number of the elements still is the same.

Remaining tasks

Reviews needed.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC, I think this looks great.

I would love to have an automated test for that, but its not necessary.

I will see if I have time on the weekend.