/** * @inheritdoc */ protected function normaliseRenderOptions() { $options = parent::normaliseRenderOptions(); $options['attributes'] = ArrayUtilities::mergeHtmlAttributes(array('id' => $this->getField()->getName() . '-field'), $options['attributes']); return $options; }
/** * @inheritdoc */ public function render(array &$output) { $output[] = sprintf('<input%s />', HtmlUtilities::attributes(ArrayUtilities::mergeHtmlAttributes($this->getRenderOption('attributes'), array('value' => $this->getFieldValue())))); }
/** * Display a form. * * @param \Sitegear\View\ViewInterface $view * @param \Symfony\Component\HttpFoundation\Request $request * @param string $formKey Unique key of the form, used for session storage and also is the key used to retrieve the * form data, if it is not supplied directly. * @param array|null $values Values to set manually into the form before displaying it. Note this is used for * rendering the form only, these values are not set into the session. These values are merged into the values * currently stored in the session (these values take precedence). * @param array[]|null $errors Errors to set manually into the form before displaying it. These errors are merged * into the errors currently stored in the session (these errors take precedence). */ public function formComponent(ViewInterface $view, Request $request, $formKey, array $values = null, array $errors = null) { LoggerRegistry::debug('FormsModule::formComponent()'); // Retrieve the form object. $form = $this->registry()->getForm($formKey, $request); // Disable the back button if the previous step is not available. $currentStep = $this->registry()->getCurrentStep($formKey); $availableSteps = $this->registry()->getAvailableSteps($formKey); if (!in_array($currentStep - 1, $availableSteps) && is_array($form->getBackButtonAttributes())) { $form->setBackButtonAttributes(array_merge($form->getBackButtonAttributes(), array('disabled' => 'disabled'))); } // Setup the view. $view['form-renderer'] = $this->createRendererFactory()->createFormRenderer($form, $currentStep); // TODO Something better here $view['form-renderer']->setRenderOption('attributes', ArrayUtilities::mergeHtmlAttributes(array('id' => $formKey . '-form'), $view['form-renderer']->getRenderOption('attributes'))); $view['values'] = array_merge($this->registry()->getValues($formKey), $values ?: array()); $view['errors'] = array_merge($this->registry()->getErrors($formKey), $errors ?: array()); // Remove errors as they are about to be displayed (they are already set in the view), and we don't want to // show the same errors again. $this->registry()->clearErrors($formKey); }