/** * Prepare options for rendering * * @param array $options * @return array */ protected function prepareOptions(array $options = []) { $helper = $this->formHelper; $this->options = $helper->mergeOptions($this->options, $options); if ($this->getOption('attr.multiple') && !$this->getOption('tmp.multipleBracesSet')) { $this->name = $this->name . '[]'; $this->setOption('tmp.multipleBracesSet', true); } if ($this->parent->haveErrorsEnabled()) { $this->addErrorClass(); } if ($this->getOption('required') === true) { $lblClass = $this->getOption('label_attr.class', ''); $requiredClass = $helper->getConfig('defaults.required_class', 'required'); if (!str_contains($lblClass, $requiredClass)) { $lblClass .= ' ' . $requiredClass; $this->setOption('label_attr.class', $lblClass); $this->setOption('attr.required', 'required'); } } if ($this->parent->clientValidationEnabled() && ($rules = $this->getOption('rules'))) { $rulesParser = new RulesParser($this); $attrs = $this->getOption('attr') + $rulesParser->parse($rules); $this->setOption('attr', $attrs); } $this->setOption('wrapperAttrs', $helper->prepareAttributes($this->getOption('wrapper'))); $this->setOption('errorAttrs', $helper->prepareAttributes($this->getOption('errors'))); if ($this->getOption('is_child')) { $this->setOption('labelAttrs', $helper->prepareAttributes($this->getOption('label_attr'))); } if ($this->getOption('help_block.text')) { $this->setOption('help_block.helpBlockAttrs', $helper->prepareAttributes($this->getOption('help_block.attr'))); } return $this->options; }
/** @test */ public function it_parses_the_alpha_rule() { $this->assertEquals(['pattern' => '[a-zA-Z]+', 'title' => $this->getTitle('alpha')], $this->parser->parse('alpha')); }