public function FeaturesManager::mergeInfoArray in Features 8.3
Same name and namespace in other branches
- 8.4 src/FeaturesManager.php \Drupal\features\FeaturesManager::mergeInfoArray()
Merges two info arrays and processes the resulting array.
Ensures values are unique and sorted.
@fixme Should this be moved to the package object or a related helper?
Parameters
array $info1: The first array.
array $info2: The second array.
string[] $keys: Keys to merge. If not specified, all keys present will be merged.
Return value
array An array with the merged and processed results.
Overrides FeaturesManagerInterface::mergeInfoArray
File
- src/
FeaturesManager.php, line 1047
Class
- FeaturesManager
- The FeaturesManager provides helper functions for building packages.
Namespace
Drupal\featuresCode
public function mergeInfoArray(array $info1, array $info2, array $keys = []) {
// If keys were specified, use only those.
if (!empty($keys)) {
$info2 = array_intersect_key($info2, array_fill_keys($keys, NULL));
}
$info = NestedArray::mergeDeep($info1, $info2);
// Merge dependencies. Preserve constraints.
// Handle cases of mixed "project:module" and "module" dependencies.
$dependencies = [];
// First collect dependency list from info1.
if (!empty($info1['dependencies'])) {
foreach ($info1['dependencies'] as $dependency_string) {
$dependency = Dependency::createFromString($dependency_string);
$dependencies[$dependency
->getName()] = $this
->getDependencyString($dependency);
}
}
// Now merge dependencies from info2.
if (!empty($info2['dependencies'])) {
foreach ($info2['dependencies'] as $dependency_string) {
$dependency = Dependency::createFromString($dependency_string);
$dependency_name = $dependency
->getName();
if (isset($dependencies[$dependency_name])) {
// Dependency already in list, so only overwrite if there is a constraint.
if ($dependency
->getConstraintString()) {
$dependencies[$dependency_name] = $this
->getDependencyString($dependency);
}
}
else {
// Wasn't in info1, so merge it into list.
$dependencies[$dependency_name] = $this
->getDependencyString($dependency);
}
}
}
if (!empty($dependencies)) {
$info['dependencies'] = array_values($dependencies);
sort($info['dependencies']);
}
// Process themes keys.
$keys = [
'themes',
];
foreach ($keys as $key) {
if (isset($info[$key]) && is_array($info[$key])) {
// NestedArray::mergeDeep() may produce duplicate values.
$info[$key] = array_unique($info[$key]);
sort($info[$key]);
}
}
return $info;
}