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

Added tab 'all'; Fixed bug with missing selection of current tab #33

Merged
merged 5 commits into from
Oct 5, 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: 22 additions & 8 deletions Admin/ArticleJsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,55 @@ class ArticleJsConfig implements JsConfigInterface
*/
private $typeConfiguration;

/**
* @var bool
*/
private $displayTabAll;

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

/**
* {@inheritdoc}
*/
public function getParameters()
{
$types = [];
$config = [
'types' => [],
'displayTabAll' => $this->displayTabAll,
];

foreach ($this->structureManager->getStructures('article') as $structure) {
$type = $this->getType($structure->getStructure());
if (!array_key_exists($type, $types)) {
$types[$type] = [
if (!array_key_exists($type, $config['types'])) {
$config['types'][$type] = [
'default' => $structure->getKey(),
'title' => $this->getTitle($type),
];
}
}

return $types;
return $config;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'sulu_article.types';
return 'sulu_article';
}

/**
Expand Down
5 changes: 5 additions & 0 deletions Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use FOS\RestBundle\Routing\ClassResourceInterface;
use JMS\Serializer\SerializationContext;
use ONGR\ElasticsearchBundle\Service\Manager;
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
use ONGR\ElasticsearchDSL\Query\TermQuery;
use ONGR\ElasticsearchDSL\Query\WildcardQuery;
use ONGR\ElasticsearchDSL\Sort\FieldSort;
Expand Down Expand Up @@ -93,6 +94,10 @@ public function cgetAction(Request $request)
$search->addQuery(new TermQuery('type', $type));
}

if (null === $search->getQueries()) {
$search->addQuery(new MatchAllQuery());
}

$count = $repository->count($search);

if (null !== $restHelper->getSortColumn()) {
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->scalarNode('display_tab_all')->defaultTrue()->info("Display tab 'all' in list view")->end()
->end();

return $treeBuilder;
Expand Down
7 changes: 4 additions & 3 deletions DependencyInjection/SuluArticleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('sulu_articles.types', $config['types']);
$container->setParameter('sulu_articles.documents', $config['documents']);
$container->setParameter('sulu_articles.view_document.article.class', $config['documents']['article']['view']);
$container->setParameter('sulu_article.types', $config['types']);
$container->setParameter('sulu_article.documents', $config['documents']);
$container->setParameter('sulu_article.view_document.article.class', $config['documents']['article']['view']);
$container->setParameter('sulu_article.display_tab_all', $config['display_tab_all']);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ Install bundle over composer:
composer require sulu/article-bundle
```

Possible bundle configurations:

```yml
sulu_article:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you add some info (comment above) you could use bin/console config:dump-reference sulu_article (where you get a commented version of the config-tree) to generate this section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, that means I can remove this part from the README?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no replace it with the output of this command

documents:
article:
view: Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument
types:

# Prototype
name:
translation_key: ~

# Display tab 'all' in list view
display_tab_all: true
```

Configure the bundles:

```yml
Expand Down
11 changes: 6 additions & 5 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
</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>
<argument>%sulu_article.types%</argument>
<argument>%sulu_article.display_tab_all%</argument>

<tag name="sulu.js_config"/>
<tag name="sulu.context" context="admin"/>
Expand All @@ -27,7 +28,7 @@
<!-- view -->
<service id="sulu_article.view_document.factory"
class="Sulu\Bundle\ArticleBundle\Document\Index\DocumentFactory">
<argument type="string">%sulu_articles.documents%</argument>
<argument type="string">%sulu_article.documents%</argument>
</service>
<service id="sulu_article.elastic_search.article_indexer"
class="Sulu\Bundle\ArticleBundle\Document\Index\ArticleIndexer">
Expand Down Expand Up @@ -153,21 +154,21 @@
<argument type="service" id="es.manager.live"/>
<argument type="service" id="sulu_document_manager.document_manager"/>
<argument type="service" id="sulu_article.content.data_provider.proxy_factory"/>
<argument type="string">%sulu_articles.view_document.article.class%</argument>
<argument type="string">%sulu_article.view_document.article.class%</argument>

<tag name="sulu.smart_content.data_provider" alias="articles"/>
</service>
<service id="sulu_article.teaser.provider" class="Sulu\Bundle\ArticleBundle\Teaser\ArticleTeaserProvider">
<argument type="service" id="es.manager.live"/>
<argument type="string">%sulu_articles.view_document.article.class%</argument>
<argument type="string">%sulu_article.view_document.article.class%</argument>

<tag name="sulu.teaser.provider" alias="article"/>
</service>

<!-- serialization -->
<service id="sulu_article.serializer.event_subscriber"
class="Sulu\Bundle\ArticleBundle\EventListener\ArticleViewDocumentSerializeSubscriber">
<argument>%sulu_articles.types%</argument>
<argument>%sulu_article.types%</argument>

<tag name="jms_serializer.event_subscriber" />
<tag name="sulu.context" context="admin"/>
Expand Down
2 changes: 1 addition & 1 deletion Resources/public/dist/components/articles/list/main.js

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

2 changes: 1 addition & 1 deletion Resources/public/dist/main.js

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

Loading