Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractSource.php
Go to the documentation of this file.
1 <?php
7 
16 abstract class AbstractSource implements
17  \Magento\Eav\Model\Entity\Attribute\Source\SourceInterface,
19 {
25  protected $_attribute;
26 
32  protected $_options = null;
33 
41  public function setAttribute($attribute)
42  {
43  $this->_attribute = $attribute;
44  return $this;
45  }
46 
53  public function getAttribute()
54  {
55  return $this->_attribute;
56  }
57 
64  public function getOptionText($value)
65  {
66  $options = $this->getAllOptions();
67  // Fixed for tax_class_id and custom_design
68  if (sizeof($options) > 0) {
69  foreach ($options as $option) {
70  if (isset($option['value']) && $option['value'] == $value) {
71  return isset($option['label']) ? $option['label'] : $option['value'];
72  }
73  }
74  }
75  // End
76  if (isset($options[$value])) {
77  return $options[$value];
78  }
79  return false;
80  }
81 
86  public function getOptionId($value)
87  {
88  foreach ($this->getAllOptions() as $option) {
89  if (strcasecmp($option['label'], $value) == 0 || $option['value'] == $value) {
90  return $option['value'];
91  }
92  }
93  return null;
94  }
95 
106  {
107  return $this;
108  }
109 
116  public function getFlatColumns()
117  {
118  return [];
119  }
120 
127  public function getFlatIndexes()
128  {
129  return [];
130  }
131 
140  public function getFlatUpdateSelect($store)
141  {
142  return null;
143  }
144 
152  public function getIndexOptionText($value)
153  {
154  return $this->getOptionText($value);
155  }
156 
163  public function toOptionArray()
164  {
165  return $this->getAllOptions();
166  }
167 }
addValueSortToCollection($collection, $dir=\Magento\Framework\Data\Collection::SORT_ORDER_DESC)
$value
Definition: gender.phtml:16