Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented is-published function for route-provider #7

Merged
merged 2 commits into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Admin/ArticleJsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ class ArticleJsConfig implements JsConfigInterface
*/
private $structureManager;

/**
* @var array
*/
private $typeConfiguration;

/**
* @param StructureManagerInterface $structureManager
* @param $typeConfiguration
*/
public function __construct(StructureManagerInterface $structureManager)
public function __construct(StructureManagerInterface $structureManager, $typeConfiguration)
{
$this->structureManager = $structureManager;
$this->typeConfiguration = $typeConfiguration;
}

/**
Expand All @@ -44,7 +51,10 @@ public function getParameters()
foreach ($this->structureManager->getStructures('article') as $structure) {
$type = $this->getType($structure->getStructure());
if (!array_key_exists($type, $types)) {
$types[$type] = $structure->getKey();
$types[$type] = [
'default' => $structure->getKey(),
'title' => $this->getTitle($type),
];
}
}

Expand All @@ -58,4 +68,20 @@ public function getName()
{
return 'sulu_article.types';
}

/**
* Returns title for given type.
*
* @param string $type
*
* @return string
*/
private function getTitle($type)
{
if (!array_key_exists($type, $this->typeConfiguration)) {
return ucfirst($type);
}

return $this->typeConfiguration[$type]['translation_key'];
}
}
12 changes: 11 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('sulu_article');
$treeBuilder->root('sulu_article')
->children()
->arrayNode('types')
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('translation_key')->end()
->end()
->end()
->end()
->end();

return $treeBuilder;
}
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/SuluArticleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('sulu_articles.types', $config['types']);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</service>
<service id="sulu_article.js_config" class="Sulu\Bundle\ArticleBundle\Admin\ArticleJsConfig">
<argument type="service" id="sulu.content.structure_manager"/>
<argument>%sulu_articles.types%</argument>

<tag name="sulu.js_config"/>
<tag name="sulu.context" context="admin"/>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading