/**
* Merge the HTML document head data
*
* @param array $data The document head data in array form
*
* @return HtmlDocument|void instance of $this to allow chaining or void for empty input data
*
* @since 1.7.0
*/
public function mergeHeadData($data)
{
if (empty($data) || !\is_array($data)) {
return;
}
$this->title = isset($data['title']) && !empty($data['title']) && !stristr($this->title, $data['title']) ? $this->title . $data['title'] : $this->title;
$this->description = isset($data['description']) && !empty($data['description']) && !stristr($this->description, $data['description']) ? $this->description . $data['description'] : $this->description;
$this->link = $data['link'] ?? $this->link;
if (isset($data['metaTags'])) {
foreach ($data['metaTags'] as $type1 => $data1) {
$booldog = $type1 === 'http-equiv';
foreach ($data1 as $name2 => $data2) {
$this->setMetaData($name2, $data2, $booldog);
}
}
}
$this->_links = isset($data['links']) && !empty($data['links']) && \is_array($data['links']) ? array_unique(array_merge($this->_links, $data['links']), SORT_REGULAR) : $this->_links;
$this->_styleSheets = isset($data['styleSheets']) && !empty($data['styleSheets']) && \is_array($data['styleSheets']) ? array_merge($this->_styleSheets, $data['styleSheets']) : $this->_styleSheets;
if (isset($data['style'])) {
foreach ($data['style'] as $type => $styles) {
foreach ($styles as $hash => $style) {
if (!isset($this->_style[strtolower($type)][$hash])) {
$this->addStyleDeclaration($style, $type);
}
}
}
}
$this->_scripts = isset($data['scripts']) && !empty($data['scripts']) && \is_array($data['scripts']) ? array_merge($this->_scripts, $data['scripts']) : $this->_scripts;
if (isset($data['script'])) {
foreach ($data['script'] as $type => $scripts) {
foreach ($scripts as $hash => $script) {
if (!isset($this->_script[strtolower($type)][$hash])) {
$this->addScriptDeclaration($script, $type);
}
}
}
}
$this->_custom = isset($data['custom']) && !empty($data['custom']) && \is_array($data['custom']) ? array_unique(array_merge($this->_custom, $data['custom'])) : $this->_custom;
if (!empty($data['scriptOptions'])) {
foreach ($data['scriptOptions'] as $key => $scriptOptions) {
$this->addScriptOptions($key, $scriptOptions, true);
}
}
// Restore asset manager state
$wa = $this->getWebAssetManager();
if (!empty($data['assetManager']['registryFiles'])) {
$waRegistry = $wa->getRegistry();
foreach ($data['assetManager']['registryFiles'] as $registryFile) {
$waRegistry->addRegistryFile($registryFile);
}
}
if (!empty($data['assetManager']['assets'])) {
foreach ($data['assetManager']['assets'] as $assetType => $assets) {
foreach ($assets as $asset) {
$wa->registerAsset($assetType, $asset)->useAsset($assetType, $asset->getName());
}
}
}
return $this;
}