Selaa lähdekoodia

Add a fallback to improve mopa compatibility if MopaBootstrapBundle is not present

Thomas Rabaix 11 vuotta sitten
vanhempi
commit
e80003c107

+ 60 - 0
Form/Extension/Field/Type/MopaCompatibilityTypeFieldExtension.php

@@ -0,0 +1,60 @@
+<?php
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Form\Extension\Field\Type;
+
+use Symfony\Component\Form\AbstractTypeExtension;
+use Symfony\Component\Form\FormInterface;
+use Symfony\Component\Form\FormView;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
+/**
+ * This class is built to allow AdminInterface to work properly
+ * if the MopaBootstrapBundle is not installed
+ *
+ * Class MopaCompatibilityTypeFieldExtension
+ *
+ * @package Sonata\AdminBundle\Form\Extension\Field\Type
+ */
+class MopaCompatibilityTypeFieldExtension extends AbstractTypeExtension
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function setDefaultOptions(OptionsResolverInterface $resolver)
+    {
+        $resolver->setDefaults(array(
+            'horizontal_label_class'         => '',
+            'horizontal_label_offset_class'  => '',
+            'horizontal_input_wrapper_class' => '',
+        ));
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function buildView(FormView $view, FormInterface $form, array $options)
+    {
+        $view->vars['horizontal_label_class']         = $options['horizontal_label_class'];
+        $view->vars['horizontal_label_offset_class']  = $options['horizontal_label_offset_class'];
+        $view->vars['horizontal_input_wrapper_class'] = $options['horizontal_input_wrapper_class'];
+    }
+
+    /**
+     * Returns the name of the type being extended.
+     *
+     * @return string The name of the type being extended
+     */
+    public function getExtendedType()
+    {
+        return 'form';
+    }
+}

+ 4 - 0
Resources/config/form_types.xml

@@ -33,6 +33,10 @@
             <argument />
         </service>
 
+        <service id="sonata.admin.form.extension.field.mopa" class="Sonata\AdminBundle\Form\Extension\Field\Type\MopaCompatibilityTypeFieldExtension">
+            <tag name="form.type_extension" alias="form" />
+        </service>
+
         <!-- Form Filter Type -->
         <service id="sonata.admin.form.filter.type.number" class="Sonata\AdminBundle\Form\Type\Filter\NumberType">
             <tag name="form.type" alias="sonata_type_filter_number" />