public function attachToCompound(Compound $root, $prepend = false)
 {
     $this->root = $root;
     if (!$root->getComponents()->contains($this)) {
         $root->getComponents()->add($this);
     }
     /** @var PartInterface $this */
     $parentId = $this->getDestinationParentId();
     if ($parentId === Compound::ROOT_ID) {
         if ($this->parent() !== $root) {
             $root->children()->add($this, $prepend);
             return;
         }
     } else {
         $parts = $root->getComponents();
         /** @var ContainerPartInterface $parent */
         $parent = $parts->findByProperty('id', $parentId, true);
         if (!$parent) {
             $id = $this->getId();
             throw new RuntimeException("Trying to attach compound part '{$id}' to not existing '{$parentId}'.");
         }
         if (!$parent instanceof ContainerPartInterface) {
             $id = $this->getId();
             throw new RuntimeException("Trying to attach compound part '{$id}' to invalid container '{$parentId}'.");
         }
         if ($this->parent() !== $parent->getContainer()) {
             $parent->getContainer()->children()->add($this, $prepend);
             return;
         }
     }
     return;
 }
 public function testComponentSet()
 {
     $c = new Compound([new Part(new Tag('div'), 'container'), new Part(new DataView('[1]'), '1', 'container'), new Part(new DataView('[2]'), '2', 'container')]);
     $c->setComponent($c3 = new DataView('[3]'), '3', 'container');
     self::assertEquals('<div>[1][2][3]</div>', $c->render());
     // @todo preserve component position when replacing
     //        $c->setComponent($c2 = new DataView('[-2-]'), '2', 'container');
     //        self::assertEquals(
     //            '<div>[1][-2-][3]</div>',
     //            $c->render()
     //        );
     //        self::assertTrue($c2 === $c->getComponent('2'));
     self::assertTrue($c3 === $c->getComponent('3'));
     $c->removeComponent('1');
     $c->removeComponent('2');
     self::assertEquals('<div>[3]</div>', $c->render());
     $c->removeComponent('container');
     self::assertEquals('', $c->render());
 }
示例#3
0
 public function attachToCompound(Compound $root, $prepend = false)
 {
     // prepend component that will render results
     $root->children()->add(new DataView(function () {
         if ($this->inputOption->hasValue()) {
             $this->renderCsv();
         }
     }), true);
     parent::attachToCompound($root, $prepend);
 }
 /**
  * Renders component and returns output.
  *
  * @return string
  */
 public function render()
 {
     $this->prepare();
     return parent::render();
 }
 /**
  * @return string
  */
 public function demo6()
 {
     $panel = new Tag('div', ['class' => 'panel panel-success']);
     $header = new Tag('div', ['class' => 'panel-heading'], []);
     $caption = new TagWithText('b', 'Panel Header');
     $body = new TagWithText('div', 'Panel Body', ['class' => 'panel-body']);
     $footer = new TagWithText('div', 'Panel Footer', ['class' => 'panel-footer']);
     $compound = new Compound([new Part($panel, 'panel'), new Part($header, 'header', 'panel'), new Part($caption, 'caption', 'header'), new Part($body, 'body', 'panel'), new Part($footer, 'footer', 'panel')]);
     $compound->addChild(new TagWithText('p', 'Text added after footer'));
     BootstrapStyling::applyTo($this->layout());
     return $this->page($compound, 'Usage of Compounds');
 }
 /**
  * Renders layout.
  *
  * @return string rendered layout
  */
 public function render()
 {
     $this->moveChildrenToMainSection();
     $this->getTemplate()->mergeData($this->getData())->mergeData(['layout' => $this]);
     return parent::render();
 }