I am trying to show/edit postgis point type. I am using creof/doctrine2-spatial
package which provides some neat functions to get X and Y values for a point. The following works fine in edit/new form so the point is listed as 'Y X' (in this case "latitude longitude").
I am not sure if this is the correct way to accomplish what I need, but it works.
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', 'text')
->add('coords', 'text', array(
'data'=>
$this->getSubject()->getCoords()->getLatitude() . ' ' .
$this->getSubject()->getCoords()->getLongitude()
));
}
However the problem is the list views. Because point is converted to string as "X Y"
it prints the latitude and longitude in wrong order in list view. It prints as "longitude latitude" I am very new to sonata so I am not exactly sure how to solve the issue in list view.
Any ideas?
Update: Thanks to @kunicmarko20 I have resolved the issue:
So the file goes to app/Resources/views/SonataAdmin/CRUD/geography_point_list.html.twig
I decided to put the file to a reasonable folder.
The contents of the template is:
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field %}
<div>
{{ object.coords.getLatitude }} {{ object.coords.getLongitude }}
</div>
{% endblock %}
The code for using the template was:
->add('coords', null, ['template' => 'SonataAdmin/CRUD/geography_point_list.html.twig']);
For some reason I couldn't get the :
type path to work?
For your list view field, you can create custom template as explained here.
Example:
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('yourfiled', null, ['template' => 'AppBundle:Admin:your_field_list.html.twig'])
;
}
And your template would look like:
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field %}
<div>
{{ object.longitude }} {{ object.latitude }}
</div>
{% endblock %}
The object here is your entity with all values.