Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeAdapter.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 
16 {
20  private $attribute;
21 
25  private $attributeCode;
26 
31  public function __construct(
33  string $attributeCode
34  ) {
35  $this->attribute = $attribute;
36  $this->attributeCode = $attributeCode;
37  }
38 
44  public function isFilterable(): bool
45  {
46  return $this->getAttribute()->getIsFilterable() || $this->getAttribute()->getIsFilterableInSearch();
47  }
48 
54  public function isSearchable(): bool
55  {
56  return $this->getAttribute()->getIsSearchable()
57  || ($this->getAttribute()->getIsVisibleInAdvancedSearch()
58  || $this->isFilterable());
59  }
60 
66  public function isAlwaysIndexable(): bool
67  {
68  // List of attributes which are required to be indexable
69  $alwaysIndexableAttributes = [
70  'category_ids',
71  'visibility',
72  ];
73 
74  return in_array($this->getAttributeCode(), $alwaysIndexableAttributes, true);
75  }
76 
82  public function isDateTimeType(): bool
83  {
84  return in_array($this->getAttribute()->getBackendType(), ['timestamp', 'datetime'], true);
85  }
86 
92  public function isFloatType(): bool
93  {
94  return $this->getAttribute()->getBackendType() === 'decimal';
95  }
96 
102  public function isIntegerType(): bool
103  {
104  return in_array($this->getAttribute()->getBackendType(), ['int', 'smallint'], true);
105  }
106 
112  public function isBooleanType(): bool
113  {
114  return in_array($this->getAttribute()->getFrontendInput(), ['select', 'boolean'], true)
115  && $this->getAttribute()->getBackendType() !== 'varchar';
116  }
117 
123  public function isComplexType(): bool
124  {
125  return in_array($this->getAttribute()->getFrontendInput(), ['select', 'multiselect'], true)
126  || $this->getAttribute()->usesSource();
127  }
128 
134  public function isEavAttribute(): bool
135  {
136  return $this->getAttribute() instanceof \Magento\Eav\Api\Data\AttributeInterface;
137  }
138 
144  public function getAttributeCode(): string
145  {
146  return $this->attributeCode;
147  }
148 
154  public function isUserDefined(): string
155  {
156  return $this->getAttribute()->getIsUserDefined();
157  }
158 
164  public function getFrontendInput()
165  {
166  return $this->getAttribute()->getFrontendInput();
167  }
168 
174  private function getAttribute(): CustomAttributesDataInterface
175  {
176  return $this->attribute;
177  }
178 }
__construct(CustomAttributesDataInterface $attribute, string $attributeCode)
$attributeCode
Definition: extend.phtml:12