Skip to content

Commit

Permalink
Merge pull request #27 from kitsunet/remove-resource-publisher
Browse files Browse the repository at this point in the history
TASK: Adapt to ``ResourceManager``
  • Loading branch information
robertlemke committed Nov 23, 2016
2 parents 01392e2 + bb85e43 commit d6e0a32
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions Classes/TYPO3/Form/ViewHelpers/RenderHeadViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use Neos\FluidAdaptor\Core\ViewHelper\Exception as ViewHelperException;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\ResourceManagement\Publishing\ResourcePublisher;
use TYPO3\Flow\ResourceManagement\ResourceManager;
use TYPO3\Form\Factory\ArrayFormFactory;

/**
Expand All @@ -29,9 +29,9 @@ class RenderHeadViewHelper extends AbstractViewHelper

/**
* @Flow\Inject
* @var ResourcePublisher
* @var ResourceManager
*/
protected $resourcePublisher;
protected $resourceManager;

/**
* @Flow\Inject
Expand All @@ -49,30 +49,12 @@ public function render($presetName = 'default')
$presetConfiguration = $this->formBuilderFactory->getPresetConfiguration($presetName);
$stylesheets = isset($presetConfiguration['stylesheets']) ? $presetConfiguration['stylesheets'] : [];
foreach ($stylesheets as $stylesheet) {
$content .= sprintf('<link href="%s" rel="stylesheet">', $this->resolveResourcePath($stylesheet['source']));
$content .= sprintf('<link href="%s" rel="stylesheet">', $this->resourceManager->getPublicPackageResourceUriByPath($stylesheet['source']));
}
$javaScripts = isset($presetConfiguration['javaScripts']) ? $presetConfiguration['javaScripts'] : [];
foreach ($javaScripts as $javaScript) {
$content .= sprintf('<script src="%s"></script>', $this->resolveResourcePath($javaScript['source']));
$content .= sprintf('<script src="%s"></script>', $this->resourceManager->getPublicPackageResourceUriByPath($javaScript['source']));
}
return $content;
}

/**
* @param string $resourcePath
* @return string
* @throws ViewHelperException
*/
protected function resolveResourcePath($resourcePath)
{
// TODO: This method should be somewhere in the resource manager probably?
$matches = [];
preg_match('#resource://([^/]*)/Public/(.*)#', $resourcePath, $matches);
if ($matches === []) {
throw new ViewHelperException('Resource path "' . $resourcePath . '" can\'t be resolved.', 1328543327);
}
$package = $matches[1];
$path = $matches[2];
return $this->resourcePublisher->getStaticResourcesWebBaseUri() . 'Packages/' . $package . '/' . $path;
}
}

0 comments on commit d6e0a32

Please sign in to comment.