public function ProductAttributeFieldManager::getFieldMap in Commerce Core 8.2
Gets a map of attribute fields across variation types.
Parameters
string $variation_type_id: (Optional) The product variation type ID. When given, used to filter the returned maps.
Return value
array If a product variation type ID was given, a list of maps. Otherwise, a list of maps grouped by product variation type ID. Each map is an array with the following keys:
- attribute_id: The attribute id;
- field_name: The attribute field name.
The maps are ordered by the weight of the attribute fields on the default product variation form display.
Overrides ProductAttributeFieldManagerInterface::getFieldMap
File
- modules/
product/ src/ ProductAttributeFieldManager.php, line 101
Class
- ProductAttributeFieldManager
- Default implementation of the ProductAttributeFieldManagerInterface.
Namespace
Drupal\commerce_productCode
public function getFieldMap($variation_type_id = NULL) {
if (!isset($this->fieldMap)) {
if ($cached_map = $this->cache
->get('commerce_product.attribute_field_map')) {
$this->fieldMap = $cached_map->data;
}
else {
$this->fieldMap = $this
->buildFieldMap();
$this->cache
->set('commerce_product.attribute_field_map', $this->fieldMap);
}
}
if ($variation_type_id) {
// The map is empty for any variation type that has no attribute fields.
return isset($this->fieldMap[$variation_type_id]) ? $this->fieldMap[$variation_type_id] : [];
}
else {
return $this->fieldMap;
}
}