public function __invoke(OutputBuffer $out) { foreach ($this->flashes->pullMessages() as $message) { $builder = new TagBuilder('div'); $builder->addClass($this->class)->addClass('kk-flash')->addClass($message->getType()); switch ($message->getType()) { case FlashMessage::ERROR: $builder->addClass($this->error); break; case FlashMessage::WARNING: $builder->addClass($this->warning); break; case FlashMessage::SUCCESS: $builder->addClass($this->success); break; case FlashMessage::INFO: $builder->addClass($this->info); break; } $old = $this->expressContext->set('flash', $message); try { $message = $this->renderNestedNodes($out->createBuffer()); $out->writeTag($builder, $message, false); } finally { $this->expressContext->set('flash', $old); } } }
/** * {@inheritdoc} */ public function __invoke(OutputBuffer $out) { $builder = new TagBuilder('form'); $this->populatePassthroughAttributes($builder); $builder->addClass('kk'); $builder->set('method', strtolower($this->method)); $builder->set('accept-charset', strtolower($out->getEncoding())); $builder->setBoolean('novalidate', $this->novalidate); if (NULL !== ($action = $this->action)) { $builder->set('action', $action); } if (!$builder->has('enctype')) { $builder->set('enctype', $this->upload ? Http::FORM_MULTIPART_ENCODED : Http::FORM_ENCODED); } $buffer = $this->renderNestedNodes($out->createBuffer(), $builder); $out->writeTag($builder, $buffer, false); }
/** * {@inheritdoc} */ public function __invoke(OutputBuffer $out) { $builder = new TagBuilder('textarea'); $this->populatePassthroughAttributes($builder); $inspection = $this->inspectAttribute('bind'); $bind = $inspection->value; if (NULL !== ($name = $this->name)) { $builder->set('name', $name); } elseif (NULL !== $inspection->name) { $builder->set('name', $inspection->name); } $builder->addClass('kk'); $builder->setBoolean('disabled', $this->disabled); $builder->setBoolean('readonly', $this->readonly); $this->renderNestedNodes($out->createBuffer(), $builder); $out->writeTag($builder, $bind === NULL ? '' : $bind); }
/** * {@inheritdoc} */ public function __invoke(OutputBuffer $out) { $options = $this->options; $multiple = $this->multiple; if (!is_array($options) && !is_object($options)) { throw new \InvalidArgumentException(sprintf('Invalid combobox options: "%s"', gettype($options))); } $builder = new TagBuilder('select'); $this->populatePassthroughAttributes($builder); $inspection = $this->inspectAttribute('bind'); if (NULL !== ($name = $this->name)) { $builder->set('name', $name . ($multiple ? '[]' : '')); } elseif (NULL !== $inspection->name) { $builder->set('name', $inspection->name); } $builder->addClass('kk'); $builder->setBoolean('disabled', $this->disabled); $builder->setBoolean('multiple', $multiple); if (NULL !== ($placeholder = $this->placeholder)) { $builder->set('data-placeholder', $placeholder); } $bind = $inspection->value; if ($multiple) { if ($bind === NULL || is_scalar($bind)) { $bound = [(string) $bind]; } else { if (!is_array($bind) && !$bind instanceof \Traversable) { throw new \InvalidArgumentException(sprintf('Invalid combobox bound value: "%s"', gettype($bind))); } $bound = []; foreach ($bind as $tmp) { $bound[] = (string) $tmp; } } } else { $bound = (array) $bind; } $buffer = $this->renderNestedNodes($out->createBuffer(), $builder); if ($options instanceof GroupedOptions) { foreach ($options->getOptions() as $group => $entries) { $buffer .= '<optgroup label="' . $out->escape($group) . '">'; foreach ($entries as $k => $v) { $buffer .= '<option value="' . $out->escape($k); if (in_array((string) $k, $bound, true)) { $buffer .= '" selected="selected'; } $buffer .= '">' . $out->escape($v) . '</option>'; } $buffer .= '</optgroup>'; } } else { foreach ($options as $k => $v) { $buffer .= '<option value="' . $out->escape($k); if (in_array((string) $k, $bound, true)) { $buffer .= '" selected="selected'; } $buffer .= '">' . $out->escape($v) . '</option>'; } } $out->writeTag($builder, $buffer, false); }