Exemplo n.º 1
0
 /**
  * Renders a "single child", containing a single not expandable value.
  *
  * Depending on how many characters are in there, it may be toggelable.
  *
  * @param Model $model
  *   The model, which hosts all the data we need.
  *
  * @return string
  *   The generated markup from the template files.
  */
 public function renderSingleChild(Model $model)
 {
     // This one is a little bit more complicated than the others,
     // because it assembles some partials and stitches them together.
     $template = $this->getTemplateFileContent('singleChild');
     $partExpand = '';
     $partCallable = '';
     $partExtra = '';
     $data = $model->getData();
     $extra = $model->getHasExtras();
     if ($extra) {
         // We have a lot of text, so we render this one expandable (yellow box).
         $partExpand = $this->getTemplateFileContent('singleChildExpand');
     }
     if ($model->getIsCallback()) {
         // Add callable partial.
         $partCallable = $this->getTemplateFileContent('singleChildCallable');
     }
     if ($extra) {
         // Add the yellow box for large output text.
         $partExtra = $this->getTemplateFileContent('singleChildExtra');
     }
     // Stitching the classes together, depending on the types.
     $typeArray = explode(' ', $model->getType());
     $typeClasses = '';
     foreach ($typeArray as $typeClass) {
         $typeClass = 'k' . $typeClass;
         $typeClasses .= $typeClass . ' ';
     }
     // Generating our code and adding the Codegen button, if there is something
     // to generate.
     $gensource = $this->storage->codegenHandler->generateSource($model);
     if (empty($gensource)) {
         // Remove the markers, because here is nothing to add.
         $template = str_replace('{gensource}', '', $template);
         $template = str_replace('{sourcebutton}', '', $template);
     } else {
         // We add the buttton and the code.
         $template = str_replace('{gensource}', $gensource, $template);
         $template = str_replace('{sourcebutton}', $this->getTemplateFileContent('sourcebutton'), $template);
     }
     // Stitching it together.
     $template = str_replace('{expand}', $partExpand, $template);
     $template = str_replace('{callable}', $partCallable, $template);
     $template = str_replace('{extra}', $partExtra, $template);
     $template = str_replace('{name}', $model->getName(), $template);
     $template = str_replace('{type}', $model->getType(), $template);
     $template = str_replace('{type-classes}', $typeClasses, $template);
     $template = str_replace('{normal}', $model->getNormal(), $template);
     $template = str_replace('{data}', $data, $template);
     $template = str_replace('{help}', $this->renderHelp($model->getHelpid()), $template);
     $template = str_replace('{connector1}', $this->renderConnector($model->getConnector1()), $template);
     $template = str_replace('{gensource}', $gensource, $template);
     return str_replace('{connector2}', $this->renderConnector($model->getConnector2()), $template);
 }