Ver código fonte

Allow label icons on list table headers

Adrián Señor 7 anos atrás
pai
commit
5bff7fc568

+ 1 - 1
Datagrid/ListMapper.php

@@ -117,7 +117,7 @@ class ListMapper extends BaseMapper
             );
             );
         }
         }
 
 
-        if (!$fieldDescription->getLabel()) {
+        if ($fieldDescription->getLabel() !== false) {
             $fieldDescription->setOption(
             $fieldDescription->setOption(
                 'label',
                 'label',
                 $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'list', 'label')
                 $this->admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'list', 'label')

+ 14 - 1
Resources/doc/reference/action_list.rst

@@ -539,7 +539,8 @@ You can :
 - `header_style`: Customize the style of header (width, color, background, align...)
 - `header_style`: Customize the style of header (width, color, background, align...)
 - `header_class`: Customize the class of the header
 - `header_class`: Customize the class of the header
 - `collapse`: Allow to collapse long text fields with a "read more" link
 - `collapse`: Allow to collapse long text fields with a "read more" link
-- `row_align`:    Customize the alignment of the rendered inner cells
+- `row_align`: Customize the alignment of the rendered inner cells
+- `label_icon`: Add an icon before label
 
 
 .. code-block:: php
 .. code-block:: php
 
 
@@ -559,6 +560,9 @@ You can :
                 'header_style' => 'width: 35%',
                 'header_style' => 'width: 35%',
                 'collapse' => true
                 'collapse' => true
             )
             )
+            ->add('upvotes', null, array(
+                'label_icon' => 'fa fa-thumbs-o-up'
+            )
             ->add('actions', null, array(
             ->add('actions', null, array(
                 'header_class' => 'customActions',
                 'header_class' => 'customActions',
                 'row_align' => 'right'
                 'row_align' => 'right'
@@ -583,7 +587,16 @@ If you want to customise the `collapse` option, you can also give an array to ov
             )
             )
             // ...
             // ...
 
 
+If you want to show only the `label_icon`:
+
+.. code-block:: php
 
 
+            // ...
+            ->add('upvotes', null, array(
+                'label' => false,
+                'label_icon' => 'fa fa-thumbs-o-up'
+            )
+            // ...
 
 
 .. _`issues on GitHub`: https://github.com/sonata-project/SonataAdminBundle/issues/1519
 .. _`issues on GitHub`: https://github.com/sonata-project/SonataAdminBundle/issues/1519
 
 

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

@@ -175,6 +175,10 @@ th.sonata-ba-list-field-header-order-asc.sonata-ba-list-field-order-active a:hov
     margin-top: -5px;
     margin-top: -5px;
 }
 }
 
 
+.sonata-ba-list-field-header-label-icon {
+  margin-right: 2px;
+}
+
 em.sonata-ba-field-help {
 em.sonata-ba-field-help {
     display: block;
     display: block;
     color: #999;
     color: #999;

+ 4 - 1
Resources/views/CRUD/base_list.html.twig

@@ -76,7 +76,10 @@ file that was distributed with this source code.
                                             {% spaceless %}
                                             {% spaceless %}
                                                 <th class="sonata-ba-list-field-header-{{ field_description.type}} {% if sortable %} sonata-ba-list-field-header-order-{{ sort_by|lower }} {{ sort_active_class }}{% endif %}{% if field_description.options.header_class is defined %} {{ field_description.options.header_class }}{% endif %}"{% if field_description.options.header_style is defined %} style="{{ field_description.options.header_style }}"{% endif %}>
                                                 <th class="sonata-ba-list-field-header-{{ field_description.type}} {% if sortable %} sonata-ba-list-field-header-order-{{ sort_by|lower }} {{ sort_active_class }}{% endif %}{% if field_description.options.header_class is defined %} {{ field_description.options.header_class }}{% endif %}"{% if field_description.options.header_style is defined %} style="{{ field_description.options.header_style }}"{% endif %}>
                                                     {% if sortable %}<a href="{{ admin.generateUrl('list', sort_parameters) }}">{% endif %}
                                                     {% if sortable %}<a href="{{ admin.generateUrl('list', sort_parameters) }}">{% endif %}
-                                                    {{ field_description.label|trans({}, field_description.translationDomain) }}
+                                                    {% if field_description.getOption('label_icon') %}
+                                                        <i class="sonata-ba-list-field-header-label-icon {{ field_description.getOption('label_icon') }}" aria-hidden="true"></i>
+                                                    {% endif %}
+                                                    {{ field_description.label|trans({}, field_description.translationDomain)|raw }}
                                                     {% if sortable %}</a>{% endif %}
                                                     {% if sortable %}</a>{% endif %}
                                                 </th>
                                                 </th>
                                             {% endspaceless %}
                                             {% endspaceless %}