base_list_field.html.twig 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. {#
  2. This file is part of the Sonata package.
  3. (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  4. For the full copyright and license information, please view the LICENSE
  5. file that was distributed with this source code.
  6. #}
  7. <td class="sonata-ba-list-field sonata-ba-list-field-{{ field_description.type }}" objectId="{{ admin.id(object) }}"{% if field_description.options.row_align is defined %} style="text-align:{{ field_description.options.row_align }}"{% endif %}>
  8. {% set route = field_description.options.route.name|default(null) %}
  9. {% set action = route == 'show' ? 'VIEW' : route|upper %}
  10. {% if
  11. field_description.options.identifier is defined
  12. and route
  13. and action
  14. and admin.hasRoute(route)
  15. and admin.isGranted(action, action in ['VIEW', 'EDIT'] ? object : null)
  16. %}
  17. <a class="sonata-link-identifier" href="{{ admin.generateObjectUrl(route, object, field_description.options.route.parameters) }}">
  18. {%- block field %}
  19. {% spaceless %}
  20. {% if field_description.options.collapse is defined %}
  21. {% set collapse = field_description.options.collapse %}
  22. <div class="sonata-readmore"
  23. data-readmore-height="{{ collapse.height|default(40) }}"
  24. data-readmore-more="{{ collapse.more|default('read_more')|trans({}, 'SonataAdminBundle') }}"
  25. data-readmore-less="{{ collapse.less|default('read_less')|trans({}, 'SonataAdminBundle') }}">{{ value }}</div>
  26. {% else %}
  27. {{ value }}
  28. {% endif %}
  29. {% endspaceless %}
  30. {% endblock -%}
  31. </a>
  32. {% else %}
  33. {% set isEditable = field_description.options.editable is defined and field_description.options.editable and admin.isGranted('EDIT', object) %}
  34. {% set xEditableType = field_description.type|sonata_xeditable_type %}
  35. {% if isEditable and xEditableType %}
  36. {% set url = path(
  37. 'sonata_admin_set_object_field_value',
  38. admin.getPersistentParameters|default([])|merge({
  39. 'context': 'list',
  40. 'field': field_description.name,
  41. 'objectId': admin.id(object),
  42. 'code': admin.code(object)
  43. })
  44. ) %}
  45. <span {% block field_span_attributes %}class="x-editable" data-type="{{ xEditableType }}" data-value="{{ field_description.type == 'date' and value is not empty ? value.format('Y-m-d') : value }}" data-title="{{ field_description.label|trans({}, field_description.translationDomain) }}" data-pk="{{ admin.id(object) }}" data-url="{{ url }}" {% endblock %}>
  46. {{ block('field') }}
  47. </span>
  48. {% else %}
  49. {{ block('field') }}
  50. {% endif %}
  51. {% endif %}
  52. </td>