/**
* Set the HTML document head data
*
* @param array $data The document head data in array form
*
* @return HtmlDocument|null instance of $this to allow chaining or null for empty input data
*
* @since 1.7.0
*/
public function setHeadData($data)
{
if (empty($data) || !\is_array($data)) {
return null;
}
$this->title = $data['title'] ?? $this->title;
$this->description = $data['description'] ?? $this->description;
$this->link = $data['link'] ?? $this->link;
$this->_metaTags = $data['metaTags'] ?? $this->_metaTags;
$this->_links = $data['links'] ?? $this->_links;
$this->_styleSheets = $data['styleSheets'] ?? $this->_styleSheets;
$this->_style = $data['style'] ?? $this->_style;
$this->_scripts = $data['scripts'] ?? $this->_scripts;
$this->_script = $data['script'] ?? $this->_script;
$this->_custom = $data['custom'] ?? $this->_custom;
$this->scriptOptions = isset($data['scriptOptions']) && !empty($data['scriptOptions']) ? $data['scriptOptions'] : $this->scriptOptions;
// 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;
}