Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultResolver.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14  as FieldTypeResolver;
16  as FieldTypeConverterInterface;
17 
22 {
26  private $fieldTypeResolver;
27 
31  private $fieldTypeConverter;
32 
37  public function __construct(
38  FieldTypeResolver $fieldTypeResolver,
39  FieldTypeConverterInterface $fieldTypeConverter
40  ) {
41  $this->fieldTypeResolver = $fieldTypeResolver;
42  $this->fieldTypeConverter = $fieldTypeConverter;
43  }
44 
52  public function getFieldName(AttributeAdapter $attribute, $context = []): ?string
53  {
54  $fieldType = $this->fieldTypeResolver->getFieldType($attribute);
55  $attributeCode = $attribute->getAttributeCode();
56  $frontendInput = $attribute->getFrontendInput();
57  if (empty($context['type'])) {
58  $fieldName = $attributeCode;
59  } elseif ($context['type'] === FieldMapperInterface::TYPE_FILTER) {
60  if ($this->isStringServiceFieldType($fieldType)) {
61  return $this->getFieldName(
62  $attribute,
63  array_merge($context, ['type' => FieldMapperInterface::TYPE_QUERY])
64  );
65  }
66  $fieldName = $attributeCode;
67  } elseif ($context['type'] === FieldMapperInterface::TYPE_QUERY) {
68  $fieldName = $this->getQueryTypeFieldName($frontendInput, $fieldType, $attributeCode);
69  } else {
70  $fieldName = 'sort_' . $attributeCode;
71  }
72 
73  return $fieldName;
74  }
75 
82  private function isStringServiceFieldType(string $serviceFieldType): bool
83  {
84  $stringTypeKey = $this->fieldTypeConverter->convert(FieldTypeConverterInterface::INTERNAL_DATA_TYPE_STRING);
85 
86  return $serviceFieldType === $stringTypeKey;
87  }
88 
97  private function getQueryTypeFieldName($frontendInput, $fieldType, $attributeCode)
98  {
99  if ($attributeCode === '*') {
100  $fieldName = '_all';
101  } else {
102  $fieldName = $this->getRefinedFieldName($frontendInput, $fieldType, $attributeCode);
103  }
104  return $fieldName;
105  }
106 
115  private function getRefinedFieldName($frontendInput, $fieldType, $attributeCode)
116  {
117  $stringTypeKey = $this->fieldTypeConverter->convert(FieldTypeConverterInterface::INTERNAL_DATA_TYPE_STRING);
118  switch ($frontendInput) {
119  case 'select':
120  case 'multiselect':
121  return in_array($fieldType, [$stringTypeKey, 'integer'], true)
122  ? $attributeCode . '_value'
123  : $attributeCode;
124  case 'boolean':
125  return $fieldType === 'integer' ? $attributeCode . '_value' : $attributeCode;
126  default:
127  return $attributeCode;
128  }
129  }
130 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(FieldTypeResolver $fieldTypeResolver, FieldTypeConverterInterface $fieldTypeConverter)
$attributeCode
Definition: extend.phtml:12