addComponent() public method

Adds the specified component to the IContainer.
public addComponent ( Nette\ComponentModel\IComponent $component, $name, $insertBefore = NULL ) : self
$component Nette\ComponentModel\IComponent
return self
Exemplo n.º 1
0
 /**
  * @param string $name
  * @throws InvalidArgumentException
  * @throws NotImplementedException
  * @return EntityBuilder
  */
 public function relationBuilder($name)
 {
     $class = $this->getMetadata();
     if (!$class->hasAssociation($name)) {
         throw new InvalidArgumentException("Entity {$this->metadata->name} has no association '{$name}'.");
     }
     if (isset($this->relationBuilders[$name])) {
         return $this->relationBuilders[$name];
     }
     if ($class->isSingleValuedAssociation($name)) {
         if (!$this->container->getComponent($name, FALSE)) {
             $this->container->addComponent(new Nette\Forms\Container(), $name);
         }
         $builder = new EntityBuilder($this->container[$name], $this->mapper, $this->controlFactory, $this->em);
         if ($this->entity && ($relation = $class->getFieldValue($this->entity, $name))) {
             $builder->bindEntity($relation);
         } else {
             $builder->bindEntityType($class->getAssociationTargetClass($name));
         }
         return $this->relationBuilders[$name] = $builder;
     } else {
         throw new NotImplementedException();
     }
 }
Exemplo n.º 2
0
 /**
  * @param IControlConfig         $config
  * @param \Nette\Forms\Container $container
  * @throws \NForms\Exceptions\UnexpectedValueException
  * @return Forms\Controls\BaseControl
  */
 protected function createControl(IControlConfig $config, Forms\Container $container)
 {
     // Before
     if ($this->beforeControlCreateOp) {
         $this->beforeControlCreateOp->beforeCreateControl($config);
     }
     // Create
     $control = $this->controlFactory->createControl($config);
     if (!$control instanceof Forms\Controls\BaseControl) {
         throw new UnexpectedValueException("Control created by factory has to be subclass of Nette\\Forms\\Controls\\BaseControl, given " . (is_object($control) ? get_class($control) : gettype($control)) . ".");
     }
     $container->addComponent($control, $config->getComponentName());
     // Set attributes
     if (($placeholder = $config->getPlaceholder()) !== NULL) {
         $placeholder = $control->translate($placeholder);
         $control->controlPrototype->addAttributes(array('placeholder' => $placeholder));
     }
     if (($description = $config->getDescription()) !== NULL) {
         $control->setOption('description', $description);
     }
     $control->controlPrototype->addAttributes($config->getAttributes());
     $control->setRequired($config->getRequired());
     // After
     if ($this->afterControlCreateOp) {
         $this->afterControlCreateOp->afterCreateControl($control, $config);
     }
     // Add control to groups
     foreach ($config->getGroups() as $groupConfig) {
         $group = self::getControlGroup($container, $groupConfig);
         $group->add($control);
     }
     return $control;
 }
Exemplo n.º 3
0
 /**
  * @param \Nette\ComponentModel\IComponent $component
  * @param $name
  * @param null $insertBefore
  * @return \Nette\ComponentModel\Container|\Nette\Forms\Container
  */
 public function addComponent(Nette\ComponentModel\IComponent $component, $name, $insertBefore = NULL)
 {
     $group = $this->currentGroup;
     $this->currentGroup = NULL;
     parent::addComponent($component, $name, $insertBefore);
     $this->currentGroup = $group;
     return $this;
 }
 /**
  * @param Forms\Container $container
  * @param string $name
  * @param RepositoryContainer $orm
  * @param NULL|bool $editable
  */
 public static function addEditorSelector(Forms\Container $container, $name, RepositoryContainer $orm, $editable = FALSE)
 {
     $container->addComponent(new self($orm, $editable), $name);
 }
Exemplo n.º 5
0
 /**
  * @param Nette\Forms\Container $parent
  * @param string $name
  * @param IFormEntity|NULL $entity
  * @return Container
  */
 protected function addContainer(Nette\Forms\Container $parent, $name, IFormEntity $entity = NULL)
 {
     $container = $this->getContainerFactory($name)->create($entity);
     $parent->addComponent($container, $name);
     return $container;
 }