This repository was archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Allow custom node icons #120
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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; | ||
} | ||
} |
This file contains hidden or 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,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]); | ||
} | ||
|
||
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; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,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> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?