public function initialize($instance, ServiceLocatorInterface $serviceLocator)
    {
        /* @var $serviceLocator \Zend\Form\FormElementManager\FormElementManagerV3Polyfill */

        if (!$instance instanceof HeadscriptProviderInterface) {
            return;
        }

        $scripts = $instance->getHeadscripts();

        if (!is_array($scripts) || empty($scripts)) {
            return;
        }

        /* @var $basepath \Zend\View\Helper\BasePath
         * @var $headscript \Zend\View\Helper\HeadScript */
        $services = $serviceLocator;
        $helpers  = $services->get('ViewHelperManager');
        $basepath = $helpers->get('basepath');
        $headscript = $helpers->get('headscript');

        foreach ($scripts as $script) {
            $headscript->appendFile($basepath($script));
        }
    }