本文整理汇总了PHP中Zend\Form\FormInterface::getOption方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::getOption方法的具体用法?PHP FormInterface::getOption怎么用?PHP FormInterface::getOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::getOption方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderBare
/**
* Render a form from the provided $form,
*
* @param FormInterface $form
* @param string $layout
* @param array $parameter
* @return string
*/
public function renderBare(FormInterface $form, $layout = self::LAYOUT_INLINE, $parameter = array())
{
$renderer = $this->getView();
$headscript = $renderer->plugin('headscript');
$basepath = $renderer->plugin('basepath');
$headscript->appendFile($basepath('Core/js/core.spinnerbutton.js'))->appendFile($basepath('js/select2.min.js'))->appendFile($basepath('Core/js/core.forms.js'));
$renderer->headLink()->appendStylesheet($basepath('css/select2.css'))->appendStylesheet($basepath('css/select2-bootstrap.css'));
if ($scripts = $form->getOption('headscript')) {
if (!is_array($scripts)) {
$scripts = array($scripts);
}
foreach ($scripts as $script) {
$headscript->appendFile($basepath($script));
}
}
$class = $form->getAttribute('class');
$class = preg_replace('~\\bform-[^ ]+\\b~', '', $class);
$class .= ' ' . $layout;
$form->setAttribute('class', $class);
if (method_exists($form, 'prepare')) {
$form->prepare();
}
$formContent = '';
if ($form instanceof ViewPartialProviderInterface) {
return $this->getView()->partial($form->getViewPartial(), array('element' => $form));
}
foreach ($form as $element) {
$parameterPartial = $parameter;
if (!$element->hasAttribute('id')) {
$elementId = preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $form->getName() . '-' . $element->getName());
$element->setAttribute('id', $elementId);
}
if ($element instanceof ExplicitParameterProviderInterface) {
$parameterPartial = array_merge($element->getParams(), $parameterPartial);
}
if ($element instanceof ViewPartialProviderInterface) {
$parameterPartial = array_merge(array('element' => $element, 'layout' => $layout), $parameterPartial);
$formContent .= $this->getView()->partial($element->getViewPartial(), $parameterPartial);
} else {
if ($element instanceof ViewHelperProviderInterface) {
$helper = $element->getViewHelper();
if (is_string($helper)) {
$helper = $this->getView()->plugin($helper);
}
$formContent .= $helper($element);
} else {
if ($element instanceof FieldsetInterface) {
$formContent .= $this->getView()->formCollection($element, true, $layout);
} else {
$formContent .= $this->getView()->formRow($element, null, null, $layout);
}
}
}
}
return $this->openTag($form) . $formContent . $this->closeTag();
}
示例2: __invoke
public function __invoke(FormInterface $form = null)
{
if ($form) {
if ($form->getOption('form-inline') || $this->hasClass($form, 'form-inline')) {
$form = $this->addClass($form, 'form-inline');
foreach ($form as $element) {
$element->setOption('form-inline', true);
}
} elseif ($form->getOption('form-horizontal') || $this->hasClass($form, 'form-hotizontal')) {
$form = $this->addClass($form, 'form-horizontal');
$labelCols = (int) $form->getOption('label-cols') ?: 3;
$inputCols = (int) $form->getOption('input-cols') ?: 12 - $labelCols;
foreach ($form as $element) {
$options = array_merge($element->getOptions(), ['form-horizontal' => true, 'label-cols' => $labelCols, 'input-cols' => $inputCols]);
$element->setOptions($options);
}
}
}
$markup = parent::__invoke($form);
//dump($markup);
return $markup;
}
示例3: __construct
public function __construct(FormInterface $form, EntityToForm $e2f)
{
$data = $form->getOption(self::AUTORENDER);
if (empty($data)) {
$data = array();
}
parent::__construct($data);
$this->ngModel = $this->extractValue($data, 'ngModel');
$this->hasDenotesText = $this->extractValue($data, 'suppressDenotesText') ? false : true;
$this->setZendFormElement($form);
// add explicitly defined fieldsets
if (isset($data['fieldsets'])) {
foreach ($data['fieldsets'] as $fieldsetData) {
$this->addFieldSet(new FieldSet($fieldsetData));
}
}
// set default fieldset if no fieldsets were defined
if (empty($this->children)) {
$this->addFieldSet(new FieldSet(array()));
}
$rows = array();
// add rows
if (isset($data['rows'])) {
foreach ($data['rows'] as $rowData) {
$this->addRow(new Row($rowData));
}
}
/* @var $formElement ElementInterface */
foreach ($form->getElements() as $formElement) {
$data = $formElement->getOption(self::AUTORENDER);
if (!is_array($data)) {
continue;
}
$field = Field::create($data, $formElement, $this, $e2f);
$this->addField($field);
}
}
示例4: renderFooter
/**
* @param FormInterface $form
* @return string
*/
private function renderFooter($form)
{
$markup = '';
$helper = $this->getRowHelper();
if ($helper instanceof TranslatorAwareInterface) {
$rollbackTextDomain = $helper->getTranslatorTextDomain();
if (($textDomain = $form->getOption(FormRow::TEXT_DOMAIN)) && $rollbackTextDomain === FormRow::DEFAULT_TEXT_DOMAIN) {
$helper->setTranslatorTextDomain($textDomain);
}
}
foreach (ArrayUtils::iteratorToArray($form) as $elementOrFieldset) {
foreach ($this->defaultFooterElementsByType as $type) {
if ($elementOrFieldset instanceof $type) {
$markup .= $helper($elementOrFieldset);
$elementOrFieldset->setOption(FormRow::RENDERED, true);
break;
}
}
}
if (isset($rollbackTextDomain)) {
$helper->setTranslatorTextDomain($rollbackTextDomain);
}
return $markup;
}
示例5: renderBare
/**
* Render a form from the provided $form,
*
* @param FormInterface $form
* @param string $layout
* @param array $parameter
* @return string
*/
public function renderBare(FormInterface $form, $layout = self::LAYOUT_HORIZONTAL, $parameter = array())
{
/* @var $renderer \Zend\View\Renderer\PhpRenderer
* @var $headscript \Zend\View\Helper\HeadScript
* @var $basepath \Zend\View\Helper\BasePath */
$renderer = $this->getView();
$headscript = $renderer->plugin('headscript');
$basepath = $renderer->plugin('basepath');
$headscript->appendFile($basepath('Core/js/core.spinnerbutton.js'))->appendFile($basepath('js/select2.min.js'))->appendFile($basepath('Core/js/core.forms.js'));
/* @noinspection PhpParamsInspection */
$renderer->headLink()->appendStylesheet($basepath('css/select2.css'));
if ($scripts = $form->getOption('headscript')) {
if (!is_array($scripts)) {
$scripts = array($scripts);
}
foreach ($scripts as $script) {
$headscript->appendFile($basepath($script));
}
}
$class = $form->getAttribute('class');
$class = preg_replace('~\\bform-[^ ]+\\b~', '', $class);
$class .= ' ' . $layout;
$form->setAttribute('class', $class);
$formId = $form->getAttribute('id') ?: $form->getName();
$form->setAttribute('id', preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $formId));
if (method_exists($form, 'prepare')) {
$form->prepare();
}
$formContent = '';
if ($form instanceof ViewPartialProviderInterface) {
return $renderer->partial($form->getViewPartial(), array('element' => $form));
}
/* @var $element \Zend\Form\ElementInterface */
foreach ($form as $element) {
$parameterPartial = $parameter;
if (!$element->hasAttribute('id')) {
$elementId = preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $element->getName());
$element->setAttribute('id', $elementId);
}
if ($element instanceof ExplicitParameterProviderInterface) {
/* @var $element ExplicitParameterProviderInterface */
$parameterPartial = array_merge($element->getParams(), $parameterPartial);
}
if ($element instanceof ViewPartialProviderInterface) {
/* @var $element ViewPartialProviderInterface */
$parameterPartial = array_merge(array('element' => $element, 'layout' => $layout), $parameterPartial);
/** @noinspection PhpToStringImplementationInspection */
$formContent .= $renderer->partial($element->getViewPartial(), $parameterPartial);
} elseif ($element instanceof FieldsetInterface) {
if ($element instanceof ViewHelperProviderInterface) {
/* @var $element ViewHelperProviderInterface */
$helper = $element->getViewHelper();
if (is_string($helper)) {
$helper = $renderer->plugin($helper);
}
$formContent .= $helper($element);
} else {
$formContent .= $renderer->formCollection($element, true, $layout);
}
} elseif (false !== $element->getOption('use_formrow_helper')) {
$formContent .= $renderer->formRow($element, null, null, $layout);
} else {
$formContent .= $renderer->formElement($element);
}
}
return $this->openTag($form) . $formContent . $this->closeTag();
}