Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.
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
7 changes: 7 additions & 0 deletions DependencyInjection/CmfTreeBrowserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Cmf\Bundle\TreeBrowserBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class CmfTreeBrowserExtension extends Extension implements PrependExtensionInterface
Expand Down Expand Up @@ -40,5 +42,10 @@ public function prepend(ContainerBuilder $container)
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');

$config = $this->processConfiguration(new Configuration(), $configs);
$container->setParameter('cmf_tree_browser.description.icon_map', $config['icons']);
}
}
36 changes: 36 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2017 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Cmf\Bundle\TreeBrowserBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('cmf_tree_browser');

$rootNode
->children()
->arrayNode('icons')
->useAttributeAsKey('class')
->prototype('scalar')->end()
->info('A mapping of classes/interfaces and icon classes or icon URLs used by the tree browser.')
->end()
->end()
;

return $treeBuilder;
}
}
67 changes: 67 additions & 0 deletions Description/IconEnhancer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2017 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Cmf\Bundle\TreeBrowserBundle\Description;

use Symfony\Cmf\Component\Resource\Repository\Resource\CmfResource;
use Symfony\Cmf\Component\Resource\Description\Description;
use Symfony\Cmf\Component\Resource\Description\DescriptionEnhancerInterface;
use Symfony\Cmf\Component\Resource\Puli\Api\PuliResource;

/**
* A description enhancer to add custom tree node icons.
*
* @author Wouter de Jong <wouter@wouterj.nl>
*/
class IconEnhancer implements DescriptionEnhancerInterface
{
private $iconMap;
private $classMap = [];

public function __construct(array $iconMap)
{
$this->iconMap = $iconMap;
}

public function enhance(Description $description)
{
$class = get_class($description->getResource()->getPayload());
if (isset($this->classMap[$class])) {
$class = $this->classMap[$class];
}

$description->set('icon', $this->iconMap[$class]);
Copy link
Member

Choose a reason for hiding this comment

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

What is an icon in this context? A CSS class or an image?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both are allowed in fancytree

Copy link
Member

Choose a reason for hiding this comment

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

for context, I am currently doing this:

sycms

Whereby the "image" is added to the description from any image mappings for the (resource) in the content-type component and subsequently used as the thumbnail via. an imagine resize.

Copy link
Member

@dantleech dantleech Aug 31, 2016

Choose a reason for hiding this comment

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

I think what I am trying to ask is if we can use a standard descriptor here rather than one specific to this bundle? i.e. if I were to swap the above browser for the fancy-tree browser it would be good if they would use the same icons / images.

Copy link
Member

Choose a reason for hiding this comment

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

can we somehow define this? or have a icon css class enhancer and a icon image enhancer? i guess the css class is good for e.g. image maps?

how does fancytree see whether its a class or an image url?

}

public function supports(PuliResource $resource)
{
if (!$resource instanceof CmfResource) {
return false;
}

$payload = $resource->getPayload();
$payloadClass = get_class($payload);

if (isset($this->iconMap[$payloadClass]) || isset($this->classMap[$payloadClass])) {
return true;
}

foreach (array_keys($this->iconMap) as $class) {
if (is_a($payload, $class) || is_subclass_of($payload, $class)) {
$this->classMap[$payloadClass] = $class;

return true;
}
}

return false;
}
}
5 changes: 4 additions & 1 deletion Resources/assets/js/adapter/fancytree.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export class FancytreeAdapter {

this.$tree = $elem;
var actions = this.actions;
var requestNode = this.requestNode;
var requestNodeToFancytreeNode = (requestNode) => {
if (requestNode.length === 0) {
return;
Expand All @@ -92,6 +91,10 @@ export class FancytreeAdapter {

this.pathKeyMap[fancytreeNode.refPath] = key;

if (requestNode.descriptors.hasOwnProperty('icon')) {
fancytreeNode.icon = requestNode.descriptors.icon;
}

for (let actionName in actions) {
var action = actions[actionName];
var url = action.url;
Expand Down
16 changes: 16 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="cmf_tree_browser.description.icon_enhancer"
class="Symfony\Cmf\Bundle\TreeBrowserBundle\Description\IconEnhancer"
public="false">
<argument>%cmf_tree_browser.description.icon_map%</argument>

<tag name="cmf_resource.description.enhancer" alias="cmf_tree_icons"/>
</service>
</services>

</container>
4 changes: 2 additions & 2 deletions Resources/public/js/cmf_tree_browser.fancytree.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": "^5.6|^7.0",
"symfony-cmf/resource-rest-bundle": "~1.0"
"symfony-cmf/resource-rest-bundle": "1.0.*"
},
"require-dev": {
"symfony/form": "^2.8|^3.0"
Expand Down