浏览代码

Added title_mode to display image, text or both in title

Hugo Briand 11 年之前
父节点
当前提交
6af4eea56b

+ 13 - 1
Admin/Pool.php

@@ -31,19 +31,23 @@ class Pool
 
     protected $titleLogo;
 
+    protected $titleMode;
+
     protected $options;
 
     /**
      * @param ContainerInterface $container
      * @param string             $title
      * @param string             $logoTitle
+     * @param string             $titleMode
      * @param array              $options
      */
-    public function __construct(ContainerInterface $container, $title, $logoTitle, $options = array())
+    public function __construct(ContainerInterface $container, $title, $logoTitle, $titleMode = "both", $options = array())
     {
         $this->container = $container;
         $this->title     = $title;
         $this->titleLogo = $logoTitle;
+        $this->titleMode = $titleMode;
         $this->options   = $options;
     }
 
@@ -307,6 +311,14 @@ class Pool
         return $this->title;
     }
 
+    /**
+     * @return string
+     */
+    public function getTitleMode()
+    {
+        return $this->titleMode;
+    }
+
     /**
      * @param string $name
      * @param mixed  $default

+ 5 - 0
DependencyInjection/Configuration.php

@@ -71,6 +71,11 @@ class Configuration implements ConfigurationInterface
 
                 ->scalarNode('title')->defaultValue('Sonata Admin')->cannotBeEmpty()->end()
                 ->scalarNode('title_logo')->defaultValue('bundles/sonataadmin/logo_title.png')->cannotBeEmpty()->end()
+                ->enumNode('title_mode')
+                    ->values(array('single_text', 'single_image', 'both'))
+                    ->defaultValue('both')
+                    ->cannotBeEmpty()
+                ->end()
                 ->arrayNode('options')
                     ->addDefaultsIfNotSet()
                     ->children()

+ 2 - 1
DependencyInjection/SonataAdminExtension.php

@@ -83,7 +83,8 @@ BOOM
         $pool = $container->getDefinition('sonata.admin.pool');
         $pool->replaceArgument(1, $config['title']);
         $pool->replaceArgument(2, $config['title_logo']);
-        $pool->replaceArgument(3, $config['options']);
+        $pool->replaceArgument(3, $config['title_mode']);
+        $pool->replaceArgument(4, $config['options']);
 
         $container->setParameter('sonata.admin.configuration.templates', $config['templates']);
         $container->setParameter('sonata.admin.configuration.admin_services', $config['admin_services']);

+ 1 - 0
Resources/doc/reference/configuration.rst

@@ -55,6 +55,7 @@ Full Configuration Options
                 acl_user_manager:     ~         # Name of the user manager service used to retrieve ACL users
             title:                Sonata Admin
             title_logo:           bundles/sonataadmin/logo_title.png
+            title_mode:           'both'            # 'both', 'single_text' or 'single_image'
             options:
                 html5_validate:                         true      # use html5 validation
                 confirm_exit:                           true      # enabled confirmation when quitting with unsaved changes

+ 4 - 0
Resources/public/css/styles.css

@@ -32,6 +32,10 @@ body > .header .logo {
     font-family: 'Source Sans Pro', sans-serif;
 }
 
+.logo img {
+    padding-bottom: 4px;
+}
+
 .open > .dropdown-menu {
     animation-duration: .3s;
     -webkit-animation-duration: .3s;

+ 6 - 2
Resources/views/standard_layout.html.twig

@@ -77,8 +77,12 @@ file that was distributed with this source code.
         <header class="header">
             {% block logo %}
                 <a class="logo" href="{{ url('sonata_admin_dashboard') }}">
-                    {#<img src="{{ asset(admin_pool.titlelogo) }}" alt="">#}
-                    {{ admin_pool.title }}
+                    {% if 'single_image' == admin_pool.titleMode or 'both' == admin_pool.titleMode %}
+                        <img src="{{ asset(admin_pool.titlelogo) }}" alt="{{ admin_pool.title }}">{% if 'both' == admin_pool.titleMode %}&nbsp;{% endif %}
+                    {% endif %}
+                    {% if 'single_text' == admin_pool.titleMode or 'both' == admin_pool.titleMode %}
+                        {{ admin_pool.title }}
+                    {% endif %}
                 </a>
             {% endblock %}
             {% block sonata_nav %}

+ 1 - 1
Tests/Admin/PoolTest.php

@@ -22,7 +22,7 @@ class PoolTest extends \PHPUnit_Framework_TestCase
 
     public function setUp()
     {
-        $this->pool = new Pool($this->getContainer(), 'Sonata Admin', '/path/to/pic.png', array('foo'=>'bar'));
+        $this->pool = new Pool($this->getContainer(), 'Sonata Admin', '/path/to/pic.png', 'both', array('foo'=>'bar'));
     }
 
     public function testGetGroups()