/**
  * Helper function to recurse into form elements when rendering summary.
  * 
  * @param ElementInterface $element
  * @return string
  */
 protected function renderSummaryElement(ElementInterface $element)
 {
     if ($element instanceof Hidden || false === $element->getOption('render_summary')) {
         return '';
     }
     if ($element instanceof ViewPartialProviderInterface) {
         $partial = $element->getViewPartial();
         $summaryPartial = $partial . '.summary';
         $partialParams = array('element' => $element);
         if (!$this->getView()->resolver($summaryPartial)) {
             $summaryPartial = $partial;
             $partialParams['renderSummary'] = true;
         }
         return $this->getView()->partial($summaryPartial, $partialParams);
     }
     if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) {
         $emptySummaryNotice = $this->getTranslator()->translate($element->getEmptySummaryNotice(), $this->getTranslatorTextDomain());
         $markup = sprintf('<div id="%s-empty-alert" class="empty-summary-notice alert alert-info"><p>%s</p></div>', $element->getAttribute('id'), $emptySummaryNotice);
         return $markup;
     }
     $label = $element->getLabel();
     $markup = '';
     if ($element instanceof FieldsetInterface) {
         if (!$element instanceof FormInterface && $label) {
             $markup .= '<h4>' . $label . '</h4>';
         }
         foreach ($element as $el) {
             $markup .= $this->renderSummaryElement($el);
         }
         return $markup;
     }
     $elementValue = $element instanceof \Zend\Form\Element\Textarea ? nl2br($element->getValue()) : $element->getValue();
     $markup .= '<div class="row">';
     $col = 12;
     if ($label) {
         $markup .= '<div class="col-md-3"><strong>' . $label . '</strong></div>';
         $col = 9;
     }
     $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' . '</div>';
     return $markup;
 }
示例#2
0
 /**
  * Helper function to recurse into form elements when rendering summary.
  *
  * @param ElementInterface $element
  * @return string
  */
 protected function renderSummaryElement(ElementInterface $element)
 {
     if ($element instanceof Hidden || false === $element->getOption('render_summary')) {
         return '';
     }
     if ($element instanceof ViewPartialProviderInterface) {
         $renderer = $this->getView();
         /* @var $renderer \Zend\View\Renderer\PhpRenderer */
         $origPartial = $element->getViewPartial();
         $partial = "{$origPartial}.view";
         $partialParams = array('element' => $element);
         if (!$renderer->resolver($partial)) {
             $partial = $origPartial;
             $partialParams['renderSummary'] = true;
         }
         return $renderer->partial($partial, $partialParams);
     }
     if ($element instanceof EmptySummaryAwareInterface && $element->isSummaryEmpty()) {
         /* @var $element EmptySummaryAwareInterface|ElementInterface */
         $emptySummaryNotice = $this->getTranslator()->translate($element->getEmptySummaryNotice(), $this->getTranslatorTextDomain());
         $markup = sprintf('<div id="%s-empty-alert" class="empty-summary-notice alert alert-info"><p>%s</p></div>', $element->getAttribute('id'), $emptySummaryNotice);
         return $markup;
     }
     $label = $this->getTranslator()->translate($element->getLabel());
     $markup = '';
     if ($element instanceof FieldsetInterface) {
         if (!$element instanceof FormInterface && $label) {
             $markup .= '<h4>' . $label . '</h4>';
         }
         foreach ($element as $el) {
             $markup .= $this->renderSummaryElement($el);
         }
         return $markup;
     }
     $elementValue = $element instanceof \Zend\Form\Element\Textarea ? nl2br($element->getValue()) : $element->getValue();
     if ('' != $elementValue && $element instanceof \Zend\Form\Element\Select) {
         $options = $element->getValueOptions();
         $translator = $this->getTranslator();
         if (true == $element->getAttribute('multiple')) {
             $multiOptions = [];
             foreach ($elementValue as $optionKey) {
                 if (isset($options[$optionKey])) {
                     $multiOptions['__general__'][] = $translator->translate($options[$optionKey]);
                     continue;
                 }
                 foreach ($options as $optKey => $optVal) {
                     if (!is_array($optVal) || !array_key_exists($optionKey, $optVal['options'])) {
                         continue;
                     }
                     $optGroupLabel = isset($optVal['label']) ? $translator->translate($optVal['label']) : $optKey;
                     $multiOptions[$optGroupLabel][] = $translator->translate($optVal['options'][$optionKey]);
                 }
             }
             $elementValue = [];
             foreach ($multiOptions as $optGroupLabel => $vals) {
                 $elementValue[] = "<b>{$optGroupLabel}</b><br>" . join(', ', $vals);
             }
             $elementValue = join('<br>', $elementValue) . '<br>';
         } else {
             $elementValue = $translator->translate($options[$elementValue]);
         }
     }
     if ('' != $elementValue && $element instanceof \Zend\Form\Element\File) {
         return '';
     }
     $markup .= '<div class="row">';
     $col = 12;
     if ($label) {
         $markup .= '<div class="col-md-3 yk-label"><label>' . $label . '</label></div>';
         $col = 9;
     }
     $markup .= '<div class="col-md-' . $col . '">' . $elementValue . '</div>' . '</div>';
     return $markup;
 }