{"id":269753,"date":"2015-12-07T11:56:02","date_gmt":"2015-12-07T08:56:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=269753"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=269753","title":{"rendered":"\u0412\u043d\u0435\u0434\u0440\u044f\u0435\u043c Bootstrap 3 Datepicker \u0432 SonataAdminBundle"},"content":{"rendered":"<p>       \u0412 \u044d\u0442\u043e\u0439 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c <a href=\"http:\/\/eonasdan.github.io\/bootstrap-datetimepicker\/\">\u0443\u0434\u043e\u0431\u043d\u044b\u0439 datepicker<\/a> \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0443 Symfony. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e datepicker \u0432 SonataAdminBundle \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/ec7\/a9e\/a62\/ec7a9ea6241c45838293d84e9fd28a05.png\"\/><\/p>\n<p>  \u0410 \u043c\u044b \u0435\u0433\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043c \u0432 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044b:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/a04\/8a0\/af2\/a048a0af2b0348c3bf817cdf678911a2.png\"\/><\/p>\n<p>  \u0422\u0435, \u043a\u0442\u043e \u0435\u0449\u0435 \u043c\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0441 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u043c datepicker-\u043e\u043c, \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c SonataAdminBundle, \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 <a href=\"http:\/\/habrahabr.ru\/post\/136659\/\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>. \u042f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u0430\u0434\u043c\u0438\u043d\u043a\u0430. \u041d\u0443 \u0447\u0442\u043e\u0436, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c.<\/p>\n<h4>\u0422\u0438\u043f \u043f\u043e\u043b\u044f datetime<\/h4>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435 \u0441 \u0447\u0435\u0433\u043e \u0441\u0442\u043e\u0438\u0442 \u043d\u0430\u0447\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b \u043a\u0430\u043a <a href=\"http:\/\/symfony.com\/doc\/2.7\/cookbook\/form\/create_custom_field_type.html\">\u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. \u0415\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432 namespace <i>&lt;vendor_name&gt;\\&lt;bundle_name&gt;\\Form\\Type\\<\/i> \u0438\u043d\u0430\u0447\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0443\u0433\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/insight.sensiolabs.com\/\">SensioLabsInsight<\/a> \u043f\u0440\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438.<\/p>\n<pre><code class=\"php\">namespace Acme\\Bundle\\DemoBundle\\Form\\Type\\Field;  use Symfony\\Component\\Form\\AbstractType; use Symfony\\Component\\Form\\FormView; use Symfony\\Component\\Form\\FormInterface; use Symfony\\Component\\Form\\FormBuilderInterface; use Symfony\\Component\\OptionsResolver\\OptionsResolver; use Symfony\\Component\\Form\\DataTransformerInterface;  \/\/ Symfony &gt;=2.8 \/\/use Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType;  class DateTime extends AbstractType implements DataTransformerInterface {     public function buildForm(FormBuilderInterface $builder, array $options)     {         \/\/ \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0443 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438 \u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \\DateTime         $builder-&gt;addModelTransformer($this);     }      public function transform($value)     {         return $value; \/\/ \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 DataTransformerInterface     }      public function reverseTransform($value)     {         \/\/ \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \\DateTime         return $value instanceof \\DateTime ? $value : new \\DateTime($value);     }      public function buildView(FormView $view, FormInterface $form, array $options)     {         \/\/ \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0430\u0442\u044b \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0442\u0440\u043e\u043a\u0443         if ($form-&gt;getData() instanceof \\DateTime) {             $view-&gt;vars['value'] = $form-&gt;getData()-&gt;format('Y-m-d H:i');         }         \/\/ css \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f bootstrap \u0444\u043e\u0440\u043c         $view-&gt;vars['attr']['class'] = 'form-control';     }      public function configureOptions(OptionsResolver $resolver)     {         \/\/ \u0431\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f data_class \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 DataTransformer         $resolver-&gt;setDefaults([              'data_class' =&gt; \\DateTime::class         ]);     }      public function getParent()     {         \/\/ Symfony &gt;=2.8         \/\/return TextType::class;         \/\/ Symfony &lt;2.8         return 'text';     }      public function getName()     {         return 'datetime'; \/\/ \u043c\u044b \u043f\u043e\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u0438\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 datetime     } } <\/code><\/pre>\n<p>  \u042f \u043d\u0435 \u0434\u0435\u043b\u0430\u043b \u043f\u0435\u0440\u0435\u043d\u043e\u0441 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 <a href=\"http:\/\/symfony.com\/doc\/2.7\/reference\/forms\/types\/datetime.html\">\u043e\u043f\u0446\u0438\u0439 datetime<\/a> \u0432 \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0437\u0430 \u043d\u0435\u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u044c\u044e, \u043d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e. \u0412 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <a href=\"#field-time\">\u0422\u0438\u043f \u043f\u043e\u043b\u044f Time<\/a> \u044f \u043e\u043f\u0438\u0448\u0443 \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u043f\u0446\u0438\u0438 <a href=\"http:\/\/symfony.com\/doc\/2.7\/reference\/forms\/types\/time.html#with-seconds\">with_seconds<\/a>.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0443\u043d\u043a\u0442\u043e\u043c \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u0449\u0435\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u0444\u043e\u0440\u043c (\u0442\u0435\u043c\u044b \u0434\u043b\u044f \u0444\u043e\u0440\u043c). \u0412 \u043d\u0435\u043c \u043c\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u0441\u044f \u043e\u0442 \u0442\u0435\u043c\u044b Sonata \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u0430\u0442\u044b. \u0428\u0430\u0431\u043b\u043e\u043d \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 \u0444\u0430\u0439\u0434 <i>Resources\/views\/Form\/fields.html.twig <\/i>. \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0443\u0442\u044c, \u043d\u043e \u043c\u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u0435\u0439.<\/p>\n<pre><code class=\"html\">{% extends 'SonataAdminBundle:Form:form_admin_fields.html.twig' %}  {% block datetime_widget %} {% spaceless %}     &lt;div class=&quot;input-group date form-field-datetime&quot;&gt;         &lt;input type=&quot;text&quot; {{ block('widget_attributes') }} {% if value is not empty %}value=&quot;{{ value }}&quot; {% endif %}\/&gt;         &lt;span class=&quot;input-group-addon&quot;&gt;             &lt;span class=&quot;glyphicon glyphicon-calendar&quot;&gt;&lt;\/span&gt;         &lt;\/span&gt;     &lt;\/div&gt; {% endspaceless %} {% endblock datetime_widget %} <\/code><\/pre>\n<p>  \u041a\u043b\u0430\u0441\u0441 <b>form-field-datetime<\/b> \u043d\u0430\u043c \u043f\u043e\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043d\u0430\u0432\u0435\u0448\u0438\u0432\u0430\u043d\u0438\u044f JavaScript. \u0422\u0435\u043f\u0435\u0440\u044c \u0443\u043a\u0430\u0436\u0435\u043c Sonata \u0447\u0442\u043e \u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0442\u0435\u043c\u0443 \u0434\u043b\u044f \u0444\u043e\u0440\u043c \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0432 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0435 <i>app\/config\/config.yml <\/i>\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438:<\/p>\n<pre><code>sonata_doctrine_orm_admin:     templates:         form: [ AcmeDemoBundle:Form:fields.html.twig ] <\/code><\/pre>\n<p>  \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b:<\/p>\n<pre><code>    acme.demo.form.type.datetime:         class: Acme\\Bundle\\DemoBundle\\Form\\Type\\Field\\DateTime         public: false <\/code><\/pre>\n<p>  \u041c\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0435\u0442\u043a\u0443 \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043e <a href=\"http:\/\/symfony.com\/doc\/2.7\/cookbook\/form\/create_custom_field_type.html#creating-your-field-type-as-a-service\">\u0442\u0443\u0442 <\/a>\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u044f \u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0442\u0430\u0440\u043e\u0435. \u041f\u043e \u0442\u043e\u0439 \u0436\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043e\u043d \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0432 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0444\u043e\u0440\u043c\u044b. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043b\u044f DI \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430:<\/p>\n<pre><code class=\"php\">namespace Acme\\Bundle\\DemoBundle\\DependencyInjection\\Compiler;  use Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface; use Symfony\\Component\\DependencyInjection\\ContainerBuilder;  class FormTypePass implements CompilerPassInterface {     public function process(ContainerBuilder $container)     {         $container-&gt;setAlias('form.type.datetime', 'acme.demo.form.type.datetime');     } } <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0447\u0442\u043e <b>form.type.datetime<\/b> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u043e\u043c \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e, \u0432\u043d\u043e\u0432\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0438\u0441\u0430 <b>acme.demo.form.type.datetime<\/b>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043a\u043e\u0433\u0434\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0445 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u0435 \u0442\u0438\u043f\u0430 <b>datetime <\/b>\u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0448 \u0441\u0435\u0440\u0432\u0438\u0441. \u0422\u0430\u043a \u043c\u044b \u043c\u0435\u043d\u044f\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b \u043d\u0435 \u043c\u0435\u043d\u044f\u044f \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432 \u0431\u0430\u043d\u0434\u043b:<\/p>\n<pre><code class=\"php\">namespace Acme\\Bundle\\DemoBundle  use Symfony\\Component\\HttpKernel\\Bundle\\Bundle; use Symfony\\Component\\DependencyInjection\\ContainerBuilder; use Acme\\BundleDemoBundle\\DependencyInjection\\Compiler\\FormTypePass;  class AcmeDemoBundle extends Bundle {     public function build(ContainerBuilder $container)     {         parent::build($container);         $container-&gt;addCompilerPass(new FormTypePass());     } } <\/code><\/pre>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 datepicker \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u043a\u0440\u0430\u0441\u0438\u0432\u0443\u044e \u0438 \u0443\u0434\u043e\u0431\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0432\u0435\u0441\u0438\u0442\u044c JavaScript \u0434\u043b\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u043e\u043a\u043d\u0430 \u0441 \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0434\u0430\u0442\u044b. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/887\/619\/5b1\/8876195b10b440feadb2c6372aff846b.png\"\/><\/p>\n<p>  \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043c\u044b \u0431\u0443\u0434\u0435\u043c <a href=\"http:\/\/eonasdan.github.io\/bootstrap-datetimepicker\/\">Bootstrap 3 Datepicker<\/a> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0441\u0442\u044c \u043d\u0430 <a href=\"https:\/\/packagist.org\/packages\/eonasdan\/bootstrap-datetimepicker\">packagist.org<\/a>, \u0437\u0430 \u0447\u0442\u043e \u0438\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e. \u041f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0432 composer.json:<\/p>\n<pre><code>{     &quot;require&quot;: {         \u2026         &quot;eonasdan\/bootstrap-datetimepicker&quot;: &quot;~4.17.37&quot;,         \u2026     } } <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u0439 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 \u0435\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0439 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <b>assetic <\/b>\u0447\u0442\u043e \u043c\u044b \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c. \u041f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 <i>app\/config\/config.yml<\/i> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438:<\/p>\n<pre><code>assetic:     assets:         admin-js:             inputs:                 - '%kernel.root_dir%\/..\/vendor\/eonasdan\/bootstrap-datetimepicker\/build\/js\/bootstrap-datetimepicker.min.js'                 - '@AcmeDemoBundle\/Resources\/public\/js\/admin.js'             output: js\/admin.js  sonata_admin:     templates:         layout: AcmeDemoBundle:Admin:standard_layout.html.twig <\/code><\/pre>\n<p>  \u041c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0444\u0430\u0439\u043b <i>js\/admin.js <\/i>\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0431\u0438\u043b\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u0448 datepicker \u0438 JavaScript \u043a\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0435\u0433\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0438 \u043d\u0430\u0432\u0435\u0448\u0438\u0432\u0430\u0435\u0442 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b. \u042d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0431\u0443\u0434\u0435\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <i>web\/js\/admin.js<\/i>. \u0422\u0430\u043a \u0436\u0435 \u043c\u044b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u043b\u0430\u0439\u0430\u0443\u0442 Sonata \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043d\u0430\u0448 JavaScript. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u044d\u0442\u0438\u043c \u0438 \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f: <\/p>\n<pre><code class=\"html\">{% extends 'SonataAdminBundle::standard_layout.html.twig' %}  {% block javascripts %}     {{ parent() }}     &lt;script src=&quot;{{ asset('js\/admin.js') }}&quot; type=&quot;text\/javascript&quot;&gt;&lt;\/script&gt; {% endblock %} <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <i>Resources\/public\/js\/admin.js<\/i> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0431\u0432\u044f\u0436\u0435\u043c \u043d\u0430\u0448\u0438 \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b JavaScript-\u043e\u043c.   <\/p>\n<pre><code class=\"javascript\">$(function(){     $('.form-field-datetime').datetimepicker({         format: 'YYYY-MM-DD HH:mm',         locale: 'ru'     }); }); <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u0432\u0441\u0435. \u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0441\u0431\u043e\u0440\u0443 assetic \u0438 \u0440\u0430\u0434\u0443\u0435\u043c\u0441\u044f \u0436\u0438\u0437\u043d\u0438:<\/p>\n<pre><code class=\"bash\">app\/console assetic:dump web --no-debug <\/code><\/pre>\n<p>  <a name=\"field-date\"><\/a><\/p>\n<h4>\u0422\u0438\u043f \u043f\u043e\u043b\u044f date<\/h4>\n<p>  \u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u0435 date \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u044f\u043c\u0438. \u041a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043f\u043e\u043b\u044f \u0444\u043e\u0440\u043c\u044b:<\/p>\n<pre><code class=\"php\">namespace Acme\\Bundle\\DemoBundle\\Form\\Type\\Field;  use Symfony\\Component\\Form\\AbstractType; use Symfony\\Component\\Form\\FormView; use Symfony\\Component\\Form\\FormInterface; use Symfony\\Component\\Form\\FormBuilderInterface; use Symfony\\Component\\OptionsResolver\\OptionsResolver; use Symfony\\Component\\Form\\DataTransformerInterface;  \/\/ Symfony &gt;=2.8 \/\/use Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType;  class Date extends AbstractType implements DataTransformerInterface {     public function buildForm(FormBuilderInterface $builder, array $options)     {         $builder-&gt;addModelTransformer($this);     }      public function transform($value)     {         return $value;     }      public function reverseTransform($value)     {         return $value instanceof \\DateTime ? $value : new \\DateTime($value);     }      public function buildView(FormView $view, FormInterface $form, array $options)     {         if ($form-&gt;getData() instanceof \\DateTime) {             $view-&gt;vars['value'] = $form-&gt;getData()-&gt;format('Y-m-d');         }          $view-&gt;vars['attr']['class'] = 'form-control';     }      public function configureOptions(OptionsResolver $resolver)     {         $resolver-&gt;setDefaults([              'data_class' =&gt; \\DateTime::class         ]);     }      public function getParent()     {         \/\/ Symfony &gt;=2.8         \/\/return TextType::class;         \/\/ Symfony &lt;2.8         return 'text';     }      public function getName()     {         return 'date';     } } <\/code><\/pre>\n<p>  \u0428\u0430\u0431\u043b\u043e\u043d: <\/p>\n<pre><code class=\"html\">{% block date_widget %} {% spaceless %}     &lt;div class=&quot;input-group date form-field-date&quot;&gt;         &lt;input type=&quot;text&quot; {{ block('widget_attributes') }} {% if value is not empty %}value=&quot;{{ value }}&quot; {% endif %}\/&gt;         &lt;span class=&quot;input-group-addon&quot;&gt;             &lt;span class=&quot;glyphicon glyphicon-calendar&quot;&gt;&lt;\/span&gt;         &lt;\/span&gt;     &lt;\/div&gt; {% endspaceless %} {% endblock date_widget %} <\/code><\/pre>\n<p>  \u0421\u0435\u0440\u0432\u0438\u0441:<\/p>\n<pre><code>    acme.demo.form.type.date:         class: Acme\\Bundle\\DemoBundle\\Form\\Type\\Field\\Date         public: false <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c:<\/p>\n<pre><code class=\"php\">\/\/ .. class FormTypePass implements CompilerPassInterface {     public function process(ContainerBuilder $container)     {         \/\/ ..         $container-&gt;setAlias('form.type.date', 'acme.demo.form.type.date');     } } <\/code><\/pre>\n<p>  \u041d\u0443 \u0438 JavaScript: <\/p>\n<pre><code class=\"javascript\">$(function(){     \/\/ ..      $('.form-field-date').datetimepicker({         format: 'YYYY-MM-DD',         locale: 'ru'     }); }); <\/code><\/pre>\n<p>  <a name=\"field-time\"><\/a><\/p>\n<h4>\u0422\u0438\u043f \u043f\u043e\u043b\u044f time<\/h4>\n<p>  \u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438, \u043d\u043e \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u044f\u043c\u0438. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0442\u0441\u044f \u0432\u0438\u0434\u0435\u043e \u0440\u043e\u043b\u0438\u043a\u0438 \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u043e\u043b\u0435 time \u0438 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u043c\u0443 \u043e\u043f\u0446\u0438\u044e <a href=\"http:\/\/symfony.com\/doc\/2.7\/reference\/forms\/types\/time.html#with-seconds\">with_seconds <\/a>\u0432 <i>true<\/i>. \u0412 \u043d\u043e\u0432\u043e\u043c \u043f\u043e\u043b\u0435 \u0444\u043e\u0440\u043c\u044b \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c. <\/p>\n<pre><code class=\"php\">namespace Acme\\Bundle\\DemoBundle\\Form\\Type\\Field;  use Symfony\\Component\\Form\\AbstractType; use Symfony\\Component\\Form\\FormView; use Symfony\\Component\\Form\\FormInterface; use Symfony\\Component\\Form\\FormBuilderInterface; use Symfony\\Component\\OptionsResolver\\OptionsResolver; use Symfony\\Component\\Form\\DataTransformerInterface;  \/\/ Symfony &gt;=2.8 \/\/use Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType;  class Time extends AbstractType implements DataTransformerInterface {     public function buildForm(FormBuilderInterface $builder, array $options)     {         $builder-&gt;addModelTransformer($this);     }      public function transform($value)     {         return $value;     }      public function reverseTransform($value)     {         return $value instanceof \\DateTime ? $value : new \\DateTime($value);     }      public function buildView(FormView $view, FormInterface $form, array $options)     {         if ($form-&gt;getData() instanceof \\DateTime) {             \/\/ \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u0442\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f             $view-&gt;vars['value'] = $form-&gt;getData()-&gt;format($options['with_seconds'] ? 'H:i:s' : 'H:i');         }         $view-&gt;vars['attr']['class'] = 'form-control';          \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0434\u043b\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430         $view-&gt;vars['with_seconds'] = $options['with_seconds'];     }      public function configureOptions(OptionsResolver $resolver)     {         $resolver-&gt;setDefaults([             'data_class' =&gt; \\DateTime::class,             'with_seconds' =&gt; false \/\/ \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043f\u0446\u0438\u044f \u0432\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0430         ]);     }      public function getParent()     {         \/\/ Symfony &gt;=2.8         \/\/return TextType::class;         \/\/ Symfony &lt;2.8         return 'text';     }       public function getName()     {         return 'time';     } } <\/code><\/pre>\n<p>  \u0428\u0430\u0431\u043b\u043e\u043d:<\/p>\n<pre><code class=\"html\">{% block time_widget %} {% spaceless %}     &lt;div class=&quot;input-group date form-field-time&quot; data-with-seconds=&quot;{{ with_seconds == true ? 1 : 0 }}&quot;&gt;         &lt;input type=&quot;text&quot; {{ block('widget_attributes') }} {% if value is not empty %}value=&quot;{{ value }}&quot; {% endif %}\/&gt;         &lt;span class=&quot;input-group-addon&quot;&gt;             &lt;span class=&quot;glyphicon glyphicon-time&quot;&gt;&lt;\/span&gt;         &lt;\/span&gt;     &lt;\/div&gt; {% endspaceless %} {% endblock time_widget %} <\/code><\/pre>\n<p>  \u0421\u0435\u0440\u0432\u0438\u0441:<\/p>\n<pre><code>    acme.demo.form.type.time:         class: Acme\\Bundle\\DemoBundle\\Form\\Type\\Field\\Time         public: false <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c:<\/p>\n<pre><code class=\"php\">\/\/ .. class FormTypePass implements CompilerPassInterface {     public function process(ContainerBuilder $container)     {         \/\/ ..         $container-&gt;setAlias('form.type.time', 'acme.demo.form.type.time');     } } <\/code><\/pre>\n<p>  JavaScript \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u0441\u044f:<\/p>\n<pre><code class=\"javascript\">$(function(){     \/\/ ..      $('.form-field-time') .each(function () {         var el = $(this),             options = {locale: 'ru'};         if (el.data('with-seconds') == 1) {             options.format = 'HH:mm:ss';         } else {             options.format = 'HH:mm';         }         el.datetimepicker(options); }); <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0412 \u043c\u0435\u0441\u0442\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/weareoutman.github.io\/clockpicker\/\">ClockPicker<\/a> \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0415\u0441\u043b\u0438 \u043e\u043d\u0430 \u0432\u0430\u0441 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u0442\u043e \u0432\u044b \u0441 \u043b\u0435\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0435 \u043f\u043e \u043c\u043e\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c.       <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/272513\/\"> http:\/\/habrahabr.ru\/post\/272513\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0412 \u044d\u0442\u043e\u0439 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c <a href=\"http:\/\/eonasdan.github.io\/bootstrap-datetimepicker\/\">\u0443\u0434\u043e\u0431\u043d\u044b\u0439 datepicker<\/a> \u0432 \u0430\u0434\u043c\u0438\u043d\u043a\u0443 Symfony. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e datepicker \u0432 SonataAdminBundle \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/ec7\/a9e\/a62\/ec7a9ea6241c45838293d84e9fd28a05.png\"\/><\/p>\n<p>  \u0410 \u043c\u044b \u0435\u0433\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043c \u0432 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044b:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/a04\/8a0\/af2\/a048a0af2b0348c3bf817cdf678911a2.png\"\/><\/p>\n<p>  \u0422\u0435, \u043a\u0442\u043e \u0435\u0449\u0435 \u043c\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0441 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u043c datepicker-\u043e\u043c, \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434 \u043a\u0430\u0442.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-269753","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/269753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=269753"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/269753\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=269753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=269753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=269753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}