/**
     * {@inheritdoc}
     */
    public function filterDump(AssetInterface $asset)
    {
        if (preg_match('/require_js_config\\.js$/', $asset->getSourcePath())) {
            $config = ['baseUrl' => '/', 'waitSeconds' => false, 'paths' => [], 'shim' => []];
            foreach (AssetRegistry::getAssets() as $module) {
                if ($module instanceof JavascriptModule) {
                    $path = array_key_value($this->config, 'cdn') && $module->getCdn() ? $module->getCdn() : $module->getPath();
                    $config['paths'][$module->getModuleName()] = preg_replace('/\\.js$/', '', $path);
                    if ($module->getDependencies()) {
                        $config['shim'][$module->getModuleName()]['deps'] = $module->getDependencies();
                    }
                    if ($module->getExports()) {
                        $config['shim'][$module->getModuleName()]['exports'] = $module->getExports();
                    }
                    if ($module->getInit()) {
                        $config['shim'][$module->getModuleName()]['init'] = '{function}' . $module->getInit() . '{/function}';
                    }
                }
            }
            $configJson = json_encode($config, JSON_UNESCAPED_SLASHES);
            $configJs = str_replace(['"{function}', '{/function}"', '\\"'], ['function(){', '}', '"'], $configJson);
            $content = <<<EOS
require.config({$configJs});
EOS;
            $asset->setContent($content);
        }
    }
示例#2
0
 public function testArrayKeyValue()
 {
     $array = ['id' => 1, 'name' => 'Angela', 'parents' => ['father' => ['name' => 'Tom'], 'mother' => null], 'boyfriend' => ['name' => 'Tomy'], 'age' => 18];
     self::assertEquals('Angela', array_key_value($array, 'name'));
     self::assertEquals('Tom', array_key_value($array, 'parents.father.name'));
     self::assertEquals(null, array_key_value($array, 'parents.mother.name'));
     self::assertEquals('Tomy', array_key_value($array, 'boyfriend.name'));
     self::assertEquals(18, array_key_value($array, 'age'));
     self::assertEquals(20, array_key_value($array, 'boyfriend.age', 20));
     self::assertEquals(null, array_key_value($array, 'boyfriend.parents'));
 }
示例#3
0
 /**
  * onKernelRequest.
  *
  * Manipulate the request in order to distinguish ajax requests and pjax requests
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$event->isMasterRequest() || !$request->headers->get('x-pjax') || !$request->isXmlHttpRequest()) {
         return;
     }
     if ($this->container->hasParameter('ynlo.pjax.config')) {
         $config = $this->container->getParameter('ynlo.pjax.config');
         if (array_key_value($config, 'remove_ajax_header')) {
             //convert pjax request to non ajax requests
             $request->headers->remove('X-Requested-With');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function render($view, array $parameters = [], Response $response = null)
 {
     $action = array_key_value($parameters, 'action', $this->admin->getCurrentAction());
     if ($this->isModalAction($action)) {
         $parameters['base_template'] = $this->getModalLayout();
         $parameters['admin_pool'] = $this->get('sonata.admin.pool');
         $parameters['admin'] = $this->admin;
         //By default, Pjax remove "X-Requested-With" header
         //but in some cases the modal is returned as Modal response,
         //Pjax plugin show this type of response using a modal, then is required restart the X-Requested-With header
         //to hide some contents in the view
         $this->getRequest()->headers->set('X-Requested-With', 'XMLHttpRequest');
         $modal = $this->createModal($view, $parameters, $this->admin->getClassnameLabel(), $this->admin->getIcon());
         $this->admin->configureModal($action, $modal);
         return $this->renderModal($modal);
     }
     return parent::render($view, $parameters, $response);
 }
 private function processAssetContexts(ContainerBuilder $containerBuilder)
 {
     $config = $this->processConfiguration(new Configuration(), $containerBuilder->getExtensionConfig('ynlo_assets'));
     $exclude = [];
     if ($containerBuilder->hasExtension('ynlo_admin')) {
         $exclude[] = 'bundle_ynlo_admin';
     }
     $defaultContexts = ['app' => ['include' => ['all'], 'exclude' => $exclude]];
     $config['contexts'] = array_merge_recursive($config['contexts'], $defaultContexts);
     foreach ($config['contexts'] as $context => $contextConfig) {
         $context = new AssetContext($context);
         $context->setInclude(array_key_value($contextConfig, 'include', []));
         $context->setExclude(array_key_value($contextConfig, 'exclude', []));
         $context->setOverride(array_key_value($contextConfig, 'override', []));
         if (empty($contextConfig['include'])) {
             $msg = sprintf('The context `%s` don`t have any assets to include.', $context);
             throw new \LogicException($msg);
         }
         AssetRegistry::registerAssetBundle($context->getName(), $context->getAssets());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function registerAssets(array $config, ContainerBuilder $containerBuilder)
 {
     $assets = [];
     //vendor
     $assets[] = AssetFactory::module('moment_js', 'bundles/ynloform/vendor/moment.min.js');
     if (array_key_value($config, 'datetimepicker')) {
         $assets[] = AssetFactory::module('bootstrap_datetimepicker_js', 'bundles/ynloform/vendor/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js')->setDependencies(['bootstrap', 'moment'])->addJqueryPlugin('datetimepicker');
         $assets[] = AssetFactory::asset('bootstrap_datetimepicker_css', 'bundles/ynloform/vendor/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css');
         $assets[] = AssetFactory::asset('ynlo_form_date_time_picker_js', 'bundles/ynloform/js/form_date_time_picker.yfp.js', ['yfp_config_dumper']);
     }
     $assets[] = AssetFactory::module('spectrum_colorpicker_js', 'bundles/ynloform/vendor/spectrum/spectrum.js')->addJqueryPlugin('spectrum');
     $assets[] = AssetFactory::asset('spectrum_colorpicker_css', 'bundles/ynloform/vendor/spectrum/spectrum.css');
     $assets[] = AssetFactory::asset('spectrum_colorpicker_theme_css', 'bundles/ynloform/vendor/spectrum/themes/bootstrap.css');
     //switchery does not work as module, why?
     $assets[] = AssetFactory::asset('switchery_js', 'bundles/ynloform/vendor/switchery/switchery.min.js');
     $assets[] = AssetFactory::asset('switchery_css', 'bundles/ynloform/vendor/switchery/switchery.min.css');
     if (array_key_value($config, 'select2.enabled')) {
         $assets[] = AssetFactory::module('select2_js', 'bundles/ynloform/vendor/select2/js/select2.full.min.js');
         $assets[] = AssetFactory::asset('select2_css', 'bundles/ynloform/vendor/select2/css/select2.min.css');
         if (array_key_value($config, 'select2.theme') === 'bootstrap') {
             $assets[] = AssetFactory::asset('select2_bootstrap_theme_css', 'bundles/ynloform/vendor/select2/css/select2-bootstrap.min.css');
         }
         $assets[] = AssetFactory::asset('ynlo_form_select2_js', 'bundles/ynloform/js/form_select2.yfp.js', ['yfp_config_dumper']);
     }
     $assets[] = AssetFactory::module('angular', 'bundles/ynloform/vendor/angular/angular.min.js');
     $assets[] = AssetFactory::module('angular_animate', 'bundles/ynloform/vendor/angular/angular-animate.min.js')->setModuleName('ngAnimate')->setDependencies(['angular']);
     $assets[] = AssetFactory::module('bootstrap_typeahead_js', 'bundles/ynloform/vendor/bootstrap_typeahead/bootstrap3-typeahead.min.js')->addJqueryPlugin('typeahead');
     $assets[] = AssetFactory::asset('typeahead_css', 'bundles/ynloform/vendor/typeahead/typeahead.css');
     $assets[] = AssetFactory::module('jquery_form_toggle', 'bundles/ynloform/vendor/jquery-form-toggle/jquery-form-toggle.js')->addJqueryPlugin('formToggle');
     $assets[] = AssetFactory::asset('ynlo_form_js', 'bundles/ynloform/js/form.yfp.js', ['yfp_config_dumper']);
     $assets[] = AssetFactory::asset('ynlo_form_color_picker_js', 'bundles/ynloform/js/form_color_picker.yfp.js', ['yfp_config_dumper']);
     $assets[] = AssetFactory::asset('ynlo_form_switchery_js', 'bundles/ynloform/js/form_switchery.yfp.js', ['yfp_config_dumper']);
     $assets[] = AssetFactory::asset('ynlo_form_angular_controller_js', 'bundles/ynloform/js/form_angular_controller.yfp.js', ['yfp_config_dumper']);
     $assets[] = AssetFactory::asset('ynlo_form_typeahead_js', 'bundles/ynloform/js/form_typeahead.yfp.js', ['yfp_config_dumper']);
     $assets[] = AssetFactory::asset('ynlo_form_toggle_js', 'bundles/ynloform/js/form_toggle.yfp.js', ['yfp_config_dumper']);
     return $assets;
 }
示例#7
0
 /**
  * Register all assets and modules given in the asset configuration.
  */
 private static function registerConfigAssets()
 {
     $config = self::$container->getExtensionConfig('ynlo_assets')[0];
     if (isset($config['assets'])) {
         foreach ($config['assets'] as $name => $asset) {
             self::addAsset(AssetFactory::asset($name, $asset));
         }
     }
     if (isset($config['modules'])) {
         foreach ($config['modules'] as $name => $assetConfig) {
             if (!array_key_value($assetConfig, 'asset')) {
                 $msg = sprintf('The registered javascript module `%s` don`t have a valid asset associated.', $name);
                 throw new \RuntimeException($msg);
             }
             $module = AssetFactory::module($name, $assetConfig['asset']);
             $module->setDependencies(array_key_value($assetConfig, 'deps', []));
             $module->setCdn(array_key_value($assetConfig, 'cdn'));
             $module->setExports(array_key_value($assetConfig, 'exports', []));
             $module->setInit(array_key_value($assetConfig, 'init'));
             $module->setJqueryPlugins(array_key_value($assetConfig, 'jquery_plugins', []));
             self::addAsset($module);
         }
     }
 }
示例#8
0
 function _extractGetParams($url)
 {
     App::import('Vendor', 'Cholesterol.utils');
     $page = array_key_value('page', $url);
     $rows = array_key_value('rows', $url);
     $sidx = array_key_value('sidx', $url);
     $sord = array_key_value('sord', $url);
     $_search = (bool) array_key_value('_search', $url);
     $doExport = (bool) array_key_value('doExport', $url);
     $filterMode = array_key_value('filterMode', $url);
     $gridId = urldecode(array_key_value('gridId', $url));
     $filters = urldecode(array_key_value('filters', $url));
     $filters = $filters == '' ? null : json_decode($filters);
     return compact('page', 'rows', 'sidx', 'sord', '_search', 'filters', 'filterMode', 'gridId', 'doExport');
 }
 /**
  * {@inheritdoc}
  *
  * @throws \RuntimeException
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     /** @var ChoiceView $choice */
     foreach ($view->vars['choices'] as $choice) {
         if ($options['select2_template_result']) {
             $object = $choice->value;
             if ($this->doctrine && $options['class']) {
                 $object = $this->doctrine->getRepository($options['class'])->find($object);
             }
             if (is_string($options['select2_template_result'])) {
                 $choice->attr['data-template-result'] = $this->templating->render($options['select2_template_result'], ['choice' => $choice, 'object' => $object]);
             } else {
                 $choice->attr['data-template-result'] = call_user_func_array($options['select2_template_result'], [$choice, $object]);
             }
         }
         if ($options['select2_template_selection']) {
             $object = $choice->value;
             if ($this->doctrine && $options['class']) {
                 $object = $this->doctrine->getRepository($options['class'])->find($object);
             }
             if (is_string($options['select2_template_selection'])) {
                 $choice->attr['data-template-selection'] = $this->templating->render($options['select2_template_selection'], ['choice' => $choice, 'object' => $object]);
             } else {
                 $choice->attr['data-template-selection'] = call_user_func_array($options['select2_template_selection'], [$choice, $object]);
             }
         }
     }
     if ($options['select2'] === true) {
         if ($options['autocomplete']) {
             $options['select2_options']['minimumResultsForSearch'] = 0;
             if (!isset($options['select2_options']['minimumInputLength'])) {
                 $options['select2_options']['minimumInputLength'] = $options['autocomplete_min_length'];
             }
         }
         $this->select2DefaultOptions['theme'] = array_key_value($this->formConfig, 'select2.theme', $this->select2DefaultOptions['theme']);
         $options['select2_options'] = array_merge($this->select2DefaultOptions, $options['select2_options']);
         $view->vars['attr']['select2'] = null;
         $view->vars['attr']['select2-options'] = json_encode($options['select2_options']);
     }
 }