-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'remotes/dev/1.5' into 1.5
- Loading branch information
Showing
8 changed files
with
394 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Oro\Bundle\FormBundle\Form\Type; | ||
|
||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Templating\Helper\CoreAssetsHelper; | ||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | ||
|
||
class DownloadLinksType extends AbstractType | ||
{ | ||
/** @var CoreAssetsHelper */ | ||
protected $assetHelper; | ||
|
||
/** | ||
* @param CoreAssetsHelper $assetHelper | ||
*/ | ||
public function __construct(CoreAssetsHelper $assetHelper) | ||
{ | ||
$this->assetHelper = $assetHelper; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
{ | ||
$resolver | ||
->setRequired(['source']) | ||
->setOptional(['class']) | ||
->setDefaults(['class' => '']) | ||
->setAllowedTypes(['source' => 'array']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function finishView(FormView $view, FormInterface $form, array $options) | ||
{ | ||
$view->vars['files'] = $this->getFiles($options['source']); | ||
$view->vars['class'] = $options['class']; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'oro_download_links_type'; | ||
} | ||
|
||
/** | ||
* Get files from a specified source data | ||
* | ||
* @param array $source | ||
* @return array | ||
*/ | ||
public function getFiles($source) | ||
{ | ||
$resources = []; | ||
if (isset($source['path'], $source['url'])) { | ||
$finder = new Finder(); | ||
$pathParts = explode('/', $source['path']); | ||
$fileNamePattern = array_pop($pathParts); | ||
$files = $finder->name($fileNamePattern)->in(implode(DIRECTORY_SEPARATOR, $pathParts)); | ||
/** @var \SplFileInfo[] $files */ | ||
foreach ($files as $file) { | ||
$resources[$file->getFilename()] = $this->assetHelper->getUrl( | ||
rtrim($source['url'], '/') . '/' . $file->getFilename() | ||
); | ||
} | ||
} | ||
|
||
return $resources; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.