本文整理汇总了PHP中Magento\Framework\Data\Form\Element\AbstractElement::getLabel方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractElement::getLabel方法的具体用法?PHP AbstractElement::getLabel怎么用?PHP AbstractElement::getLabel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Data\Form\Element\AbstractElement
的用法示例。
在下文中一共展示了AbstractElement::getLabel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Checkbox render function
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
/** @var \Magento\Framework\Data\Form\Element\Checkbox $checkbox */
$checkbox = $this->_elementFactory->create('checkbox', array('data' => $element->getData()));
$checkbox->setForm($element->getForm());
$elementHtml = sprintf('<div class="field no-label field-%s with-note">' . '<div class="control">' . '<div class="nested">' . '<div class="field choice"> %s' . '<label class="label" for="%s">%s</label>' . '<p class="note">%s</p>' . '</div>' . '</div>' . '</div>' . '</div>', $element->getHtmlId(), $checkbox->getElementHtml(), $element->getHtmlId(), $element->getLabel(), $element->getNote());
return $elementHtml;
}
示例2: render
/**
* render separator config row
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$fieldConfig = $element->getFieldConfig();
$htmlId = $element->getHtmlId();
$html = '<tr id="row_' . $htmlId . '">' . '<td class="label" colspan="3">';
$html .= '<div style="border-bottom: 1px solid #dfdfdf;
font-size: 15px;
color: #666;
border-left: #CCC solid 5px;
padding: 2px 12px;
text-align: left !important;
margin-left: 10%;
margin-top: 20px;">';
$html .= $element->getLabel();
$html .= '</div></td></tr>';
return $html;
}
示例3: render
/**
* @param AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function render(AbstractElement $element)
{
$countryId = false;
$isRegionRequired = false;
if ($country = $element->getForm()->getElement('country_id')) {
$countryId = $country->getValue();
$isRegionRequired = $this->_directoryHelper->isRegionRequired($countryId);
}
$html = '<div class="field field-region ' . ($isRegionRequired ? 'required' : '') . '">' . "\n";
$regionCollection = false;
if ($countryId) {
if (!isset(self::$_regionCollections[$countryId])) {
self::$_regionCollections[$countryId] = $this->_countryFactory->create()->setId($countryId)->getLoadedRegionCollection()->toOptionArray();
}
$regionCollection = self::$_regionCollections[$countryId];
}
$regionId = intval($element->getForm()->getElement('region_id')->getValue());
$htmlAttributes = $element->getHtmlAttributes();
foreach ($htmlAttributes as $key => $attribute) {
if ('type' === $attribute) {
unset($htmlAttributes[$key]);
break;
}
}
// Output two elements - for 'region' and for 'region_id'.
// Two elements are needed later upon form post - to properly set data to address model,
// otherwise old value can be left in region_id attribute and saved to DB.
// Depending on country selected either 'region' (input text) or 'region_id' (selectbox) is visible to user
$regionHtmlName = $element->getName();
$regionIdHtmlName = str_replace('region', 'region_id', $regionHtmlName);
$regionHtmlId = $element->getHtmlId();
$regionIdHtmlId = str_replace('region', 'region_id', $regionHtmlId);
if ($isRegionRequired) {
$element->addClass('required-entry');
}
if ($regionCollection && count($regionCollection) > 0) {
$elementClass = $element->getClass();
$html .= '<label class="label" for="' . $regionIdHtmlId . '"><span>' . $element->getLabel() . '</span>' . '</label>';
$html .= '<div class="control">';
$html .= '<select id="' . $regionIdHtmlId . '" name="' . $regionIdHtmlName . '" ' . $element->serialize($htmlAttributes) . '>' . "\n";
foreach ($regionCollection as $region) {
$selected = $regionId == $region['value'] ? ' selected="selected"' : '';
$regionVal = 0 == $region['value'] ? '' : (int) $region['value'];
$html .= '<option value="' . $regionVal . '"' . $selected . '>' . $this->_escaper->escapeHtml(__($region['label'])) . '</option>';
}
$html .= '</select>' . "\n";
$html .= '<input type="hidden" name="' . $regionHtmlName . '" id="' . $regionHtmlId . '" value=""/>';
$html .= '</div>';
$element->setClass($elementClass);
} else {
$html .= '<label class="label" for="' . $regionHtmlId . '"><span>' . $element->getLabel() . '</span></label>';
$html .= '<div class="control">';
$html .= '<input id="' . $regionHtmlId . '" name="' . $regionHtmlName . '" value="' . $element->getEscapedValue() . '" ' . $element->serialize($htmlAttributes) . "/>" . "\n";
$html .= '<input type="hidden" name="' . $regionIdHtmlName . '" id="' . $regionIdHtmlId . '" value=""/>';
$html .= '</div>' . "\n";
}
$html .= '</div>' . "\n";
return $html;
}
示例4: aroundGetLabelHtml
/**
* 2015-12-13
* Отличия от модифицируемого метода
* @see \Magento\Framework\Data\Form\Element\AbstractElement::getLabelHtml():
* 1) Добавляем свои классы для Font Awesome.
* 2) При использовании Font Awesome не добавляем исходную подпись
* (значением которой является класс Font Awesome)
* и выводим, по сути, пустые теги <label><span></span></label>.
* 3) Добавляем атрибут title.
* 2015-12-28
* 4) Добавляем класс, соответствующий типу элемента.
*
* Пример использования Font Awesome: https://github.com/mage2pro/core/tree/7cb37ab2c4d728bc20d29ca3c7c643e551f6eb0a/Framework/Data/Form/Element/Font.php#L40
*
* @see \Df\Framework\Form\Element\Font::onFormInitialized()
* @see \Magento\Framework\Data\Form\Element\AbstractElement::getLabelHtml()
* @param Sb|E $sb
* @param \Closure $proceed
* @param string|null $idSuffix
* @return string
*/
public function aroundGetLabelHtml(Sb $sb, \Closure $proceed, $idSuffix = '')
{
/** @var string|null|Phrase $label */
$label = $sb->getLabel();
/** @var string $result */
if (is_null($label)) {
$result = '';
} else {
$label = (string) $label;
/**
* 2015-12-25
* @see \Magento\Framework\Data\Form\Element\Multiline::getLabelHtml()
* имеет другое значение по-умолчанию параметра $idSuffix:
* public function getLabelHtml($suffix = 0)
* https://github.com/magento/magento2/blob/2.0.0/lib/internal/Magento/Framework/Data/Form/Element/Multiline.php#L59
*/
if ('' === $idSuffix && $sb instanceof Multiline) {
$idSuffix = 0;
}
/** @var bool $isFontAwesome */
$isFontAwesome = df_starts_with($label, 'fa-');
/** @var string[] $classA */
$classA = ['label', 'admin__field-label', 'df-element-' . $sb->getType()];
if ($isFontAwesome) {
$classA[] = 'fa';
$classA[] = $label;
$label = '';
}
/** @var array(string => string) $params */
$params = ['class' => df_cc_s($classA), 'for' => $sb->getHtmlId() . $idSuffix, 'data-ui-id' => E::uidSt($sb, 'label')];
/** @var string $title */
$title = (string) $sb->getTitle();
if ($title !== $label) {
$params['title'] = $title;
}
$result = df_tag('label', $params, df_tag('span', [], $label)) . "\n";
}
return $result;
}
示例5: render
/**
* Render element html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return sprintf('<tr class="system-fieldset-sub-head" id="row_%s"><td colspan="5"><h4 id="%s">%s</h4></td></tr>', $element->getHtmlId(), $element->getHtmlId(), $element->getLabel());
}