Create ui component view helper

@return Twig_SimpleFunction
198070
protected function components()
    {
        $function = function (array $params = null) {
            try {
                $this->gridStackAdapter->scripts();

                if (!empty($params)) {
                    return app('ui-components')->findAllByResourceAndNames(uri(), $params);
                }
                return app('ui-components')->findAllByResource(uri());
            } catch (Exception $e) {
                Log::emergency($e);
                return [];
            }
        };
        return new Twig_SimpleFunction(
                'components', $function
        );
    }
257609
protected function generateCreateView(AbstractResourceBundle $bundle, &$summary)
    {
        $this->generateFormView($bundle);
        $path = $bundle->getPath() . '/Resources/views/' . $this->model . '/create.html.twig';

        if (file_exists($path)) {
            $summary[] = '';
            $summary[] = '<bg=red>Create view already exist.</>';

            return;
        }

        $this->renderFile('crud/create.html.twig.twig',
            $path,
            array(
                'bundle'  => $bundle->getName(),
                'model'   => $this->model,
                'prefix'  => $this->getBundlePrefix($bundle),
                'action'  => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_create'),
                'cancel'  => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_index'),
            )
        );

        $summary[] = '';
        $summary[] = '<bg=green>Create view created.</>';
    }
841392
public function toolModalContentAction()
    {
        $id = $this->params()->fromRoute('id', $this->params()->fromQuery('id', ''));

        $melisKey = $this->params()->fromRoute('melisKey', '');
        $title    = $this->tool()->getTranslation('tr_melis_cms_prospects_theme_new_title');
        $data     = array();
        $form     = $this->getThemeForm();

        if(is_numeric($id)) {
            $title = $this->tool()->getTranslation('tr_melis_cms_prospects_theme_edit_title');
            $data  = (array) $this->themeTable()->getEntryById((int) $id)->current();
            $form->setData($data);
        }
        else {
            $form->get('pros_theme_id')->setAttribute('style', 'display:none')->setLabel('');
            $form->get('pros_theme_id')->setLabelAttributes(array('style' => 'display:none'));
        }

        $view = new ViewModel();

        $view->melisKey = $melisKey;
        $view->title    = $title;
        $view->form     = $form;

        return $view;
    }
912553
public function construct()
	{
		// Get component name from user input
		$name = null;
		if ($this->arguments->getOpt('n') || $this->arguments->getOpt('name') || $this->arguments->getOpt(4))
		{
			// Set name, according to priority of inputs
			$name = ($this->arguments->getOpt(4)) ? $this->arguments->getOpt(4) : $name;
			$name = ($this->arguments->getOpt('n')) ? $this->arguments->getOpt('n') : $name;
			$name = ($this->arguments->getOpt('name')) ? $this->arguments->getOpt('name') : $name;
			$name = strtolower($name);
		}
		else
		{
			// If name wasn't provided, and we're in interactive mode...ask for it
			if ($this->output->isInteractive())
			{
				$name = $this->output->getResponse('What do you want the component name to be?');
			}
			else
			{
				$this->output->error("Error: a component name should be provided.");
			}
		}

		// Define our install directory or get it from args
		$install_dir = PATH_CORE . DS . 'components';
		if ($this->arguments->getOpt('install-dir') && strlen(($this->arguments->getOpt('install-dir'))) > 0)
		{
			// @FIXME: need to be able to distinguish between path_app and path_core here
			$install_dir = PATH_CORE . DS . trim($this->arguments->getOpt('install-dir'), DS) . DS . 'components';
		}

		if (substr($name, 0, 4) == 'com_')
		{
			$name = substr($name, 4);
		}

		// Make sure component doesn't already exist
		if (is_dir($install_dir . DS . 'com_' . $name))
		{
			$this->output->error("Error: the component name provided ({$name}) seems to already exists.");
		}

		// Make component
		$this->addTemplateFile("{$this->getType()}.tmpl", $install_dir . DS . 'com_' . $name)
		     ->addReplacement('component_name', $name)
		     ->addReplacement('option', 'com_' . $name)
		     ->make();
	}
1178325
private function buildXmlSourceView()
	{
		$filename = '../include/demos/'.mb_strtolower($this->demo).'.xml';
		if (file_exists($filename)) {
			$this->layout_ui->getWidget('xml_source_container')->visible = true;

			$code = file_get_contents($filename);
			$code = str_replace("\t", '  ', $code);
			$code = highlight_string($code, true);

			$pre_tag = new SwatHtmlTag('pre');
			$pre_tag->setContent($code, 'text/xml');

			$this->layout_ui->getWidget('xml_source_view')->content =
				$pre_tag->toString();
		}
	}
963143
public function buildView(FormView $view, FormInterface $form, array $options) {
        if(isset($options['ad_component_addon'])) {
            switch ($options['ad_component_addon']) {
                case 'pre':
                case 'post':
                    $addons=[$options['ad_component_addon']];
                    break;
                case 'both':
                    $addons=['pre','post'];
                    break;
                default:
                    throw new LogicException('Valor "'.$options['ad_component_addon'].'" parámetro "ad_component_addon" no válido. Valores permitidos: pre|post|both');
            }
            foreach ($addons as $addon) {
                $view->vars['ad_component_addon_type_'.$addon] = is_array($options['ad_component_addon_type']) ?
                    (isset($options['ad_component_addon_type'][$addon]) ? $options['ad_component_addon_type'][$addon] : null) :
                    $options['ad_component_addon_type'];
                if(is_null($view->vars['ad_component_addon_type_'.$addon])){
                    throw new LogicException('Falta parámetro "ad_component_addon_type" para "'.$addon.'" addon');
                }
                elseif(!in_array($view->vars['ad_component_addon_type_'.$addon], ['text','button','icon'])){
                    throw new LogicException('Valor "'.$view->vars['ad_component_addon_type_'.$addon].'" parámetro "ad_component_addon_type" para "'.$addon.'" addon no válido. Valores permitidos: text|button|icon');
                }

                $view->vars['ad_component_addon_content_type_'.$addon] = is_array($options['ad_component_addon_content_type']) ?
                    (isset($options['ad_component_addon_content_type'][$addon]) ? $options['ad_component_addon_content_type'][$addon] : null) :
                    $options['ad_component_addon_content_type'];
                if($view->vars['ad_component_addon_type_'.$addon]=='button') {
                    if(is_null($view->vars['ad_component_addon_content_type_'.$addon])) {
                        throw new LogicException('Falta Parámetro "ad_component_addon_content_type" para "' . $addon . '" addon');
                    }
                    elseif(!in_array($view->vars['ad_component_addon_content_type_'.$addon], ['text','icon'])) {
                        throw new LogicException('Valor "'.$view->vars['ad_component_addon_content_type_'.$addon].'" parámetro "ad_component_addon_content_type" para "'.$addon.'" addon no válido. Valores permitidos: text|icon');
                    }
                }

                $view->vars['ad_component_addon_content_'.$addon] = is_array($options['ad_component_addon_content']) ?
                    (isset($options['ad_component_addon_content'][$addon]) ? $options['ad_component_addon_content'][$addon] : null) :
                    $options['ad_component_addon_content'];
                if(is_null($view->vars['ad_component_addon_content_'.$addon])){
                    throw new LogicException('Falta Parámetro "ad_component_addon_content" para "'.$addon.'" addon');
                }

                $view->vars['ad_component_addon_attr_'.$addon] = isset($options['ad_component_addon_attr']) ?
                    (isset($options['ad_component_addon_attr'][$addon]) ? $options['ad_component_addon_attr'][$addon] : $options['ad_component_addon_attr']) :
                    array();
            }
        }
    }
1312449
protected function componentAttributes()
    {
        $function = function ($widget) {
            $classname = array_get($widget['attributes'], 'attributes.classname');
            if (is_null($classname)) {
                return '';
            }
            $instance = null;
            $widgets  = Registry::get('ui-components');
            if (empty($widgets)) {
                return '';
            }
            foreach ($widgets as $widget) {
                if (get_class($widget) == $classname) {
                    $instance = $widget;
                    break;
                }
            }
            if (is_null($instance)) {
                return '';
            }
            return serialize($instance->getShared());
        };
        return new Twig_SimpleFunction(
                'component_attributes', $function
        );
    }
1200360
public function renderToolTemplatesModalEmptyHandlerAction()
    {
        $melisKey = $this->params()->fromRoute('melisKey', '');

        $view = new ViewModel();
        $view->melisKey = $melisKey;

        return $view;
    }
675086
public function component_templates() {
		$output = null;
		foreach ( $this->modals as $modal ) {

			$width  = 'data-width="950"';
			$height = 'data-height="550"';

			$output .= '<script type="text/html" ' . $width . ' ' . $height . ' id="' . esc_attr( $this->id() ) . '-' . esc_attr( $modal->slug ) . '">';
			if ( isset( $modal->struct['preview'] ) ) {
				$template = uix()->add( 'control', $modal->slug, array(
					'type'     => 'template',
					'template' => $modal->struct['preview'],
				) );

				$output .= $template->render();
			} else {
				$output .= '<div>' . $modal->struct['label'] . '</div>';
			}
			$output .= '</script>';

		}

		return $output;
	}
1082526
function() {
            var self = this;

            this.template = this.options.template;
            this.args = this.options.args || {};

            // Related view
            this.view = this.options.view || null;

            // Init template context
            _.extend(this.args, {
                "_": _,
                "hr": {
                    "configs": configs,
                    "urls": Urls,
                    "i18n": I18n,
                    "offline": Offline
                },
                "view": {
                    "component": function(cid, args, name, subid) {
                        name = name || cid;

                        if (!self.view) {
                            throw new Error("Error in template " + self.template + " : try to import component in a non view-related template ");
                        }

                        if (Template.components[cid] == null) {
                            throw new Error("Error in template " + self.template + " : try to import component "+cid);
                        }

                        var view = new Template.components[cid].Class(args || {}, self.view);
                        
                        self.view.addComponent(name, view);

                        var component = $("<component/>", {
                            "data-component": view.cid
                        });

                        return component[0].outerHTML;
                    }
                },
                "template": {
                    "args": this.args,
                    "name": this.template,
                    "import": function(name, args, cname) {
                        cname = cname || name;
                        return this.args.view.component("template", {template: name, args: args}, cname);
                    },
                    "htmlid": function(h) {
                        return _.escape(h);
                    }
                }
            }, Template.options);

            return this;
        }
245302
final protected function beforeRenderView()
    {
        $this->initView();
        
        $view = $this->getView();
        
        $client = $this->clientType ? : static::input('clienttype');
        if ($client) {
            $configs = Config::get('views', $this->getModule()->getName(), true);
            if (isset($configs[$client]['theme'])) {
                $view->setTheme($configs[$client]['theme']);
            }
        }
        
        if (!$view->getBeginContent()) {
            $beginContent  = "<?php use Wslim\Ioc; ?>" . PHP_EOL;
            $view->setBeginContent($beginContent);
        }
        
        // ioc
        Ioc::$htmlHelper || Ioc::$htmlHelper = new HtmlHelper();
        Ioc::$formHelper || Ioc::$formHelper = new FormHelper();
        
        // view data
        $viewData = $view->getData();
        $viewData['rootUrl']  = Config::getRootUrl();
        $viewData['baseUrl']  = $this->getModule()->getBaseUrl(true);
        $viewData['lang']     = Ioc::language()->getData();
        $viewData['requestParams'] = $this->input();
        $viewData['page']     = $this->inputInt('page');
        
        return $this;
    }
989584
function createSubComponent() {
    $output = null;
    foreach( $this->components as $component ) {
      if( '' >= $component->getConfig( 'language'))
        $component->setConfig( 'language',  $this->getConfig( 'language' ));
      $component->setConfig( 'allowEmpty',  $this->getConfig( 'allowEmpty' ));
      $component->setConfig( 'nl',          $this->getConfig( 'nl' ));
      $component->setConfig( 'unique_id',   $this->getConfig( 'unique_id' ));
      $component->setConfig( 'format',      $this->getConfig( 'format' ));
      $output .= $component->createComponent( $this->xcaldecl );
    }
    return $output;
  }
1191548
public function item_template() {
		$output = '<script type="text/html" id="' . esc_attr( $this->id() ) . '-tmpl">';
		$output .= '<div class="uix-item">';
		if ( false !== strpos( $this->child['config']->struct['view'], ABSPATH ) ) {
			ob_start();
			include $this->child['config']->struct['view'];
			$output .= ob_get_clean();
		} else {
			$output .= $this->child['config']->struct['view'];
		}
		$output .= '</div>';
		$output .= '</script>';

		return $output;
	}
1125999
public function createUiComponent(HtmlView $view) {
		if ($this->compact) {
			return $this->createCompactOutputUiComponent($view);
		}
		
		$targetUtils = (new Eiu($this->targetEiFrame))->frame();
		$panelEiPropPath = ContentItemsEiProp::getPanelEiPropPath();
		
		$groupedEiuEntries = array();
		foreach ($this->toManyEiField->getValue() as $targetRelationEntry) {
			$targetEiuEntry = null;
			if ($targetRelationEntry->hasEiEntry()) {
				$targetEiuEntry = $targetUtils->entry($targetRelationEntry->getEiEntry());
			} else {
				$targetEiuEntry = $targetUtils->entry($targetRelationEntry->getEiObject());
			}
			
			$panelName = (string) $targetEiuEntry->getValue($panelEiPropPath, true);
			if (!isset($groupedEiuEntries[$panelName])) {
				$groupedEiuEntries[$panelName] = array();
			}
			
			$groupedEiuEntries[$panelName][] = $targetEiuEntry;
		}
		
		return $view->getImport('\rocket\impl\ei\component\prop\ci\view\contentItems.html',
				array('panelLayout' => new PanelLayout($this->panelConfigs), 'groupedEiuEntries' => $groupedEiuEntries));
	}
1027372
function render() {
        //\Debug::info(TplVar::instance()->vars());
        //\Debug::info($this->layout);
        return Twig::from_template($this->layout)
                        ->set(Page_TplVar::instance()->vars())
                        ->render();
    }
896725
public function requiredComponents() {
    $twig_file_name = $declaration = str_replace('_', '-', $this->component_data['theme_hook_name']) . '.html.twig';

    $components = array(
      'hooks' => array(
        'component_type' => 'Hooks',
        'hooks' => array(
          'hook_theme' => TRUE,
        ),
      ),
      $twig_file_name => array(
        'component_type' => 'TwigFile',
        'filename' => $twig_file_name,
        'theme_hook_name' => $this->component_data['theme_hook_name'],
      ),
    );

    return $components;
  }
1152601
public function createUiField(PropertyPath $propertyPath, HtmlView $view, UiOutfitter $uiOutfitter): UiComponent {
		$ciEiTypeLabels = array();
		
		$targetContextEiMask = $this->targetEditEiFrame->getContextEiEngine()->getEiMask();
		foreach ($this->targetEditEiFrame->getContextEiEngine()->getEiMask()->getEiType()->getAllSubEiTypes() as $subEiType) {
			if ($subEiType->isAbstract()) continue;
			
			$ciEiTypeLabels[$subEiType->getId()] = $this->targetEditEiFrame->determineEiMask($subEiType)->getLabelLstr()
					->t($view->getN2nLocale());
		}
		
		return $view->getImport('\rocket\impl\ei\component\prop\ci\view\contentItemsForm.html',
				array('panelLayout' => new PanelLayout($this->panelConfigs), 'propertyPath' => $propertyPath,
						'ciEiTypeLabels' => $ciEiTypeLabels));
	}