Exemple #1
0
 /**
  * Render an element
  *
  * Introspects the element type and attributes to determine which
  * helper to utilize when rendering.
  *
  * @param  \Zend\Form\ElementInterface $element
  * @return string
  */
 public function renderElement(ElementInterface $element)
 {
     if (!method_exists($this->view, 'plugin')) {
         // Bail early if renderer is not pluggable
         return '';
     }
     if ($element instanceof HelperAwareInterface && ($plugin = $element->getRendererHelperName())) {
         $plugin = $this->tryLoadPlugin($plugin);
     }
     if (empty($plugin)) {
         $class = explode('\\', get_class($element));
         $plugin = $this->tryLoadPlugin('form_' . end($class));
     }
     if (empty($plugin)) {
         $plugin = $this->tryLoadPlugin('form_' . $element->getAttribute('type'));
     }
     if (empty($plugin)) {
         $plugin = $this->tryLoadPlugin('form_input');
     }
     $enabled = $this->isTranslatorEnabled();
     $textDomain = $this->getTranslatorTextDomain();
     if ($element instanceof TranslatorSettingsAwareInterface) {
         $enabled = $element->isTranslatorEnabled();
         if (null !== $element->getTranslatorTextDomain()) {
             $textDomain = $element->getTranslatorTextDomain();
         }
     }
     if (method_exists($plugin, 'setTranslatorEnabled')) {
         $plugin->setTranslatorEnabled($enabled);
     }
     if ($enabled) {
         if (method_exists($plugin, 'setTranslatorTextDomain')) {
             $plugin->setTranslatorTextDomain($textDomain);
         }
     }
     return $plugin($element);
 }