Beispiel #1
0
 /**
  * @inheritdoc
  */
 public function decorate($content, $length = null, $default = null)
 {
     if (is_numeric($length)) {
         $content = HtmlUtilities::excerpt(!empty($content) ? $content : $default, intval($length)) . PHP_EOL;
     }
     return $content;
 }
 /**
  * @inheritdoc
  */
 public function render(array &$output)
 {
     $value = $this->getFieldValue();
     if ($this->getField()->isArrayValue()) {
         $value = implode(', ', $value);
     }
     $output[] = sprintf('<%s%s>%s</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_ELEMENT_NAME), HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES)), strlen($value) > 0 ? $value : '&nbsp;', $this->getRenderOption(self::RENDER_OPTION_KEY_ELEMENT_NAME));
 }
 /**
  * @inheritdoc
  */
 public function render(array &$output)
 {
     $output[] = sprintf('<select%s>', HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES)));
     $value = $this->getFieldValue();
     foreach ($this->getField()->getValues() as $option) {
         $optionAttributes = array('value' => $option['value']);
         if ($option['value'] === $value) {
             $optionAttributes['selected'] = 'selected';
         }
         $output[] = sprintf('<option%s>%s</option>', HtmlUtilities::attributes($optionAttributes), $option['label']);
     }
     $output[] = '</select>';
 }
 /**
  * @inheritdoc
  */
 public function render(array &$output)
 {
     $name = $this->getField()->getName();
     $errors = $this->getField()->getForm()->getFieldErrors($name);
     if (!empty($errors)) {
         $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_ELEMENT_NAME), HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES)));
         $errorWrapperElementName = $this->getRenderOption(self::RENDER_OPTION_KEY_ERROR_WRAPPER_ELEMENT_NAME);
         $errorWrapperAttributes = HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ERROR_WRAPPER_ATTRIBUTES));
         foreach ($errors as $error) {
             $output[] = sprintf('<%s%s>%s</%s>', $errorWrapperElementName, $errorWrapperAttributes, $error, $errorWrapperElementName);
         }
         $output[] = sprintf('</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_ELEMENT_NAME));
     }
 }
 /**
  * Handle exceptions that occur during the request handling process.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
  *
  * @throws \Exception|\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException|\Symfony\Component\HttpKernel\Exception\HttpException
  *   As a fallback behaviour only, if a sensible error page cannot be generated.
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     LoggerRegistry::debug('EngineExceptionListener performing handleException() on EXCEPTION event');
     $exception = $event->getException();
     try {
         // Delete any buffered page content.
         while (ob_get_level() > 1) {
             ob_end_clean();
         }
         // Determine the status code to use for the error page (and which error page is displayed).
         $statusCode = $exception instanceof HttpException ? $exception->getStatusCode() : ($exception instanceof FileNotFoundException ? 404 : 500);
         // Set route and template attributes to error page defaults.
         $event->getRequest()->attributes->add(array('_status' => $statusCode, '_route' => $this->getEngine()->getErrorRoute($statusCode), '_route_params' => array('exception' => $exception, 'statusCode' => $statusCode), '_template' => $this->getEngine()->getErrorTemplate()));
         // Store the exception and status code in the top-level view data.
         $page = $this->getEngine()->getViewFactory()->getPage();
         $page['exception'] = $exception;
         $page['status-code'] = $statusCode;
         // Perform standard rendering using a proxy event.
         $renderer = new EngineRendererListener($this->getEngine());
         $viewScript = sprintf('error-%3d', $statusCode);
         // TODO Handle view scripts that don't exist, default back to 500 or 404
         $renderEvent = new GetResponseForControllerResultEvent($event->getKernel(), $event->getRequest(), HttpKernelInterface::SUB_REQUEST, $viewScript);
         $renderer->onKernelView($renderEvent);
         // Copy the response from the proxy event back to the event being handled.
         $event->setResponse($renderEvent->getResponse());
     } catch (\Exception $e) {
         try {
             // Delete any buffered page content.
             while (ob_get_level() > 1) {
                 ob_end_clean();
             }
             // If there is an error above, try to display the fallback error page, i.e. black-and-white error
             // message.
             $event->setResponse(Response::create(HtmlUtilities::exception($exception, $this->getEngine()->getSiteInfo()->getAdministratorName(), $this->getEngine()->getSiteInfo()->getAdministratorEmail())));
         } catch (\Exception $e2) {
             // If another error occurs, the best thing to do is throw the original error.
             throw $exception;
         }
     }
 }
Beispiel #6
0
 protected function renderChildren(array &$output)
 {
     // Back button.
     $backButtonAttributes = $this->getForm()->getBackButtonAttributes();
     if (is_array($backButtonAttributes)) {
         $backButtonAttributes['type'] = 'submit';
         $backButtonAttributes['name'] = 'back';
         if (!isset($backButtonAttributes['value'])) {
             $backButtonAttributes['value'] = 'Back';
         }
         $output[] = sprintf('<input%s />', HtmlUtilities::attributes($backButtonAttributes));
     }
     // Submit button.
     $submitButtonAttributes = $this->getForm()->getSubmitButtonAttributes();
     $submitButtonAttributes['type'] = 'submit';
     $output[] = sprintf('<input%s />', HtmlUtilities::attributes($submitButtonAttributes));
     // Reset button.
     $resetButtonAttributes = $this->getForm()->getResetButtonAttributes();
     if (is_array($resetButtonAttributes)) {
         $resetButtonAttributes['type'] = 'reset';
         $output[] = sprintf('<input%s />', HtmlUtilities::attributes($resetButtonAttributes));
     }
 }
 /**
  * @inheritdoc
  */
 public function render(array &$output)
 {
     $innerIdPrefix = sprintf('%s-%s', $this->getField()->getName(), $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ID_PREFIX));
     // Add the outer container element open tag.
     $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ELEMENT_NAME), HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ATTRIBUTES)));
     // Add a hidden field (note: using the raw field name always without [] appended) to reset the value each post.
     $output[] = sprintf('<input type="hidden" name="%s" value="" />', $this->getField()->getName());
     // Add the input elements and value labels, one for each available value.
     $value = $this->getFieldValue();
     foreach ($this->getField()->getValues() as $option) {
         // Add the input element itself.
         $optionId = sprintf('%s-%s', $innerIdPrefix, NameUtilities::convertToDashedLower($option['value']));
         $optionAttributes = array_merge($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES), array('id' => $optionId, 'value' => $option['value'], 'type' => $this->getField()->getType(), 'class' => $this->getField()->getType()));
         if (is_array($value) && in_array($option['value'], $value)) {
             $optionAttributes['checked'] = 'checked';
         }
         $input = sprintf('<input%s />', HtmlUtilities::attributes($optionAttributes));
         // Add the input label element.
         $inputLabelAttributes = array('for' => $optionId, 'class' => sprintf('multiple-input-label %s-label', $this->getField()->getType()));
         $inputLabel = sprintf('<label%s>%s</label>', HtmlUtilities::attributes($inputLabelAttributes), $option['label']);
         // Add the inner wrapper.
         $optionWrapperAttributes = $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ATTRIBUTES);
         $optionWrapperAttributes['id'] = sprintf('%s-container', $innerIdPrefix);
         $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ELEMENT_NAME), HtmlUtilities::attributes($optionWrapperAttributes));
         if ($this->getRenderOption(self::RENDER_OPTION_KEY_LABELS_FIRST)) {
             $output[] = $inputLabel;
             $output[] = $input;
         } else {
             $output[] = $input;
             $output[] = $inputLabel;
         }
         $output[] = sprintf('</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ELEMENT_NAME));
     }
     // Add the outer container element end tag.
     $output[] = sprintf('</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ELEMENT_NAME));
 }
 /**
  * @inheritdoc
  */
 public function render(array &$output)
 {
     $output[] = sprintf('<input%s />', HtmlUtilities::attributes(ArrayUtilities::mergeHtmlAttributes($this->getRenderOption('attributes'), array('value' => $this->getFieldValue()))));
 }
 /**
  * @inheritdoc
  */
 public function render(array &$output)
 {
     $output[] = sprintf('<%s%s />', 'img', HtmlUtilities::attributes(ArrayUtilities::combine($this->getRenderOption(self::RENDER_OPTION_KEY_CAPTCHA_IMAGE_ATTRIBUTES), array('src' => 'real-captcha/image'))));
     // TODO Optional reload button (basic javascript or jquery?)
     parent::render($output);
 }
Beispiel #10
0
 public function testExceptionWithAdminDetails()
 {
     $e = new \Exception('ERROR MESSAGE');
     $this->assertStringMatchesFormat("%AName: Your Administrator%A", HtmlUtilities::exception($e, 'Your Administrator', '*****@*****.**'));
     $this->assertStringMatchesFormat("%AEmail Address: admin@sitegear.org%A", HtmlUtilities::exception($e, 'Your Administrator', '*****@*****.**'));
 }
 /**
  * @inheritdoc
  */
 public function render(array &$output)
 {
     $output[] = sprintf('<label%s>%s%s</label>', HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES)), $this->getField()->getLabelText(), $this->getField()->getLabelMarkers($this->getRenderOption(self::RENDER_OPTION_KEY_MARKER_SEPARATOR)));
 }
Beispiel #12
0
 /**
  * See the documentation for __call() for details.
  *
  * @return string Rendered content.
  */
 public function __toString()
 {
     try {
         // Delegate to the render() method.
         return $this->render();
     } catch (\Exception $exception) {
         // Throwing any Exception from __toString() is a fatal error (bravo, php, bra-vo) so we have no other
         // choice but to catch any exception here and do something with it.  Delete any buffered content and
         // display a plain error page.
         // TODO Make this a proper error-500 page but prevent feedback loops
         while (ob_get_level() > 1) {
             ob_end_clean();
         }
         return HtmlUtilities::exception($exception, $this->getEngine()->getSiteInfo()->getAdministratorName(), $this->getEngine()->getSiteInfo()->getAdministratorEmail());
     }
 }
 /**
  * @inheritdoc
  */
 public function render(array &$output)
 {
     $output[] = sprintf('<textarea%s>%s</textarea>', HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES)), $this->getFieldValue());
 }
 /**
  * Render the start tag.
  *
  * @param string[] $output
  */
 protected function renderStartTag(array &$output)
 {
     $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_ELEMENT_NAME), HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES)));
 }