code: 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));
          }
      }
docs: Injects scripts to the headscript view helper.
  
  If the created instance implements {@link HeadscriptProviderInterface},
  the provided scripts will be injected in the Headscript view helper, prepended
  with the base path.
  
  @param \Zend\Form\ElementInterface | HeadscriptProviderInterface $instance
  @param ServiceLocatorInterface $serviceLocator
  
  @return void