本文整理汇总了PHP中Magento\Eav\Model\Entity\Attribute\AbstractAttribute::getValidateRules方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractAttribute::getValidateRules方法的具体用法?PHP AbstractAttribute::getValidateRules怎么用?PHP AbstractAttribute::getValidateRules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Eav\Model\Entity\Attribute\AbstractAttribute
的用法示例。
在下文中一共展示了AbstractAttribute::getValidateRules方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
/**
* Build validation rules
*
* @param AbstractAttribute $attribute
* @param array $data
* @return array
*/
public function build(AbstractAttribute $attribute, array $data)
{
$validation = [];
if (isset($data['required']) && $data['required'] == 1) {
$validation = array_merge($validation, ['required-entry' => true]);
}
if ($attribute->getFrontendInput() === 'price') {
$validation = array_merge($validation, ['validate-zero-or-greater' => true]);
}
if ($attribute->getValidateRules()) {
$validation = array_merge($validation, $attribute->getValidateRules());
}
$rules = [];
foreach ($validation as $type => $ruleName) {
$rule = [$type => $ruleName];
if ($type === 'input_validation') {
$rule = isset($this->validationRules[$ruleName]) ? $this->validationRules[$ruleName] : [];
}
$rules = array_merge($rules, $rule);
}
return $rules;
}
示例2: build
/**
* Build validation rules
*
* @param AbstractAttribute $attribute
* @param array $data
* @return array
*/
public function build(AbstractAttribute $attribute, array $data)
{
$rules = [];
if (isset($data['required']) && $data['required'] == 1) {
$rules['required-entry'] = true;
}
$validation = $attribute->getValidateRules();
if (!empty($validation)) {
foreach ($validation as $type => $ruleName) {
switch ($type) {
case 'input_validation':
if (isset($this->validationRul[$type][$ruleName])) {
$rules = array_merge($rules, $this->validationRul[$type][$ruleName]);
}
break;
case 'min_text_length':
case 'max_text_length':
$rules = array_merge($rules, [$type => $ruleName]);
break;
}
}
}
return $rules;
}
示例3: createMetadataAttribute
/**
* @param AbstractAttribute $attribute
* @return Data\Eav\AttributeMetadata
*/
private function createMetadataAttribute($attribute)
{
$data = $this->booleanPrefixMapper($attribute->getData());
// fill options and validate rules
$data[AttributeMetadata::OPTIONS] = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : array();
$data[AttributeMetadata::VALIDATION_RULES] = $attribute->getValidateRules();
// fill scope
$data[AttributeMetadata::SCOPE] = $attribute->isScopeGlobal() ? 'global' : ($attribute->isScopeWebsite() ? 'website' : 'store');
$data[AttributeMetadata::FRONTEND_LABEL] = [];
$data[AttributeMetadata::FRONTEND_LABEL][0] = array(FrontendLabel::STORE_ID => 0, FrontendLabel::LABEL => $attribute->getFrontendLabel());
if (is_array($attribute->getStoreLabels())) {
foreach ($attribute->getStoreLabels() as $storeId => $label) {
$data[AttributeMetadata::FRONTEND_LABEL][$storeId] = array(FrontendLabel::STORE_ID => $storeId, FrontendLabel::LABEL => $label);
}
}
return $this->attributeMetadataBuilder->populateWithArray($data)->create();
}