本文整理汇总了PHP中Magento\Framework\Data\Form\Element\AbstractElement::setRequired方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractElement::setRequired方法的具体用法?PHP AbstractElement::setRequired怎么用?PHP AbstractElement::setRequired使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Data\Form\Element\AbstractElement
的用法示例。
在下文中一共展示了AbstractElement::setRequired方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Output the region element and javasctipt that makes it dependent from country element
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
if ($country = $element->getForm()->getElement('country_id')) {
$countryId = $country->getValue();
} else {
return $element->getDefaultHtml();
}
$regionId = $element->getForm()->getElement('region_id')->getValue();
$html = '<div class="field field-state required">';
$element->setClass('input-text');
$element->setRequired(true);
$html .= $element->getLabelHtml() . '<div class="control">';
$html .= $element->getElementHtml();
$selectName = str_replace('region', 'region_id', $element->getName());
$selectId = $element->getHtmlId() . '_id';
$html .= '<select id="' . $selectId . '" name="' . $selectName . '" class="select required-entry" style="display:none">';
$html .= '<option value="">' . __('Please select') . '</option>';
$html .= '</select>';
$html .= '<script>' . "\n";
$html .= 'require(["prototype", "mage/adminhtml/form"], function(){';
$html .= '$("' . $selectId . '").setAttribute("defaultValue", "' . $regionId . '");' . "\n";
$html .= 'new regionUpdater("' . $country->getHtmlId() . '", "' . $element->getHtmlId() . '", "' . $selectId . '", ' . $this->_directoryHelper->getRegionJson() . ');' . "\n";
$html .= '});';
$html .= '</script>' . "\n";
$html .= '</div></div>' . "\n";
return $html;
}
示例2: testGetHtmlWithRenderer
/**
* @covers \Magento\Framework\Data\Form\Element\AbstractElement::getHtml()
*/
public function testGetHtmlWithRenderer()
{
$this->_model->setRequired(true);
$expectedHtml = 'some-html';
$rendererMock = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Form\\Element\\Renderer\\RendererInterface');
$rendererMock->expects($this->once())->method('render')->with($this->_model)->will($this->returnValue($expectedHtml));
$this->_model->setRenderer($rendererMock);
$this->assertEquals($expectedHtml, $this->_model->getHtml());
$this->assertEquals(' required-entry', $this->_model->getClass());
}
示例3: _addAdditionalFormElementData
/**
* Add additional data to form element
*
* @param AbstractElement $element
* @return $this
*/
protected function _addAdditionalFormElementData(AbstractElement $element)
{
switch ($element->getId()) {
case 'email':
$element->setRequired(0);
$element->setClass('validate-email');
break;
}
return $this;
}