/**
* Helper method to calculate inline to non inline relation (before/after positions).
* Return associated array, which contain dependency (handle) name as key, and list of inline items for each position.
* Example: ['handle.name' => ['before' => ['inline1', 'inline2'], 'after' => ['inline3', 'inline4']]]
*
* Note: If inline asset have a multiple dependencies, then will be used last one from the list for positioning
*
* @param WebAssetItem[] $assets The assets list
*
* @return array
*
* @since 4.0.0
*/
public function getInlineRelation(array $assets) : array
{
$inlineRelation = [];
// Find an inline assets and their relations to non inline
foreach ($assets as $k => $asset) {
if (!$asset->getOption('inline')) {
continue;
}
// Add to list of inline assets
$inlineAssets[$asset->getName()] = $asset;
// Check whether position are requested with dependencies
$position = $asset->getOption('position');
$position = $position === 'before' || $position === 'after' ? $position : null;
$deps = $asset->getDependencies();
if ($position && $deps) {
// If inline asset have a multiple dependencies, then use last one from the list for positioning
$handle = end($deps);
$inlineRelation[$handle][$position][$asset->getName()] = $asset;
}
}
return $inlineRelation;
}