/**
  * Execute the DisplayCommand.
  *
  * @param   DisplayCommand $command The command to execute.
  *
  * @return  void
  */
 public function handle(BasicDisplayCommand $command)
 {
     $repository = $this->getCommandBus()->handle(new RepositoryQuery($command->entityName));
     $entity = $repository->findById($command->id);
     if (!$entity instanceof EntityInterface) {
         return;
     }
     $compound = new Compound($command->entityName, $this->getElements($entity));
     $compound->accept($command->renderer);
 }
 private function registerContentTypes()
 {
     $container = $this->container;
     $output = $this->output;
     $this->output->registerContentType('TemplateSelector', function (TemplateSelector $selector) use($container, $output) {
         /** @var RepositoryInterface $repo */
         $repo = $container->get('Repository')->forEntity(Template::class);
         $templates = $repo->getAll();
         // @todo Grouping
         $groups = ['Available Templates' => $templates];
         $accordion = new Accordion('Accordion Title', null, new \stdClass());
         foreach ($groups as $title => $group) {
             $compound = new Compound('div', $title, null, new \stdClass());
             foreach ($group as $item) {
                 $imageData = new ImageEntity();
                 $imageData->url = '/' . $item->path . '/preview.png';
                 $image = new Image($imageData, $item->path);
                 $compound->add($image);
             }
             $accordion->add($compound);
         }
         $accordion->accept($output);
     });
 }
Пример #3
0
 /**
  * Render a compound (block) element
  *
  * @param   Compound $compound The compound
  *
  * @return  integer Number of bytes written to the output
  */
 public function visitCompound(Compound $compound)
 {
     $id = " id=\"{$compound->getId()}\"";
     $class = $compound->getParameter('class', '');
     if (!empty($class)) {
         $class = " class=\"{$class}\"";
     }
     $len = 0;
     $len += $this->write("<!-- Compound -->\n");
     $len += $this->write("<{$compound->getType()}{$id}{$class}>\n");
     foreach ($compound->elements as $item) {
         $len += $item->accept($this);
     }
     $len += $this->write("</{$compound->getType()}>\n");
     $len += $this->write("<!-- /Compound -->\n");
     return $len;
 }