You are here

public function ProductAttributeFieldManager::getFieldDefinitions in Commerce Core 8.2

Gets the attribute field definitions.

The field definitions are not ordered. Use the field map when the field order is important.

Parameters

string $variation_type_id: The product variation type ID.

Return value

\Drupal\Core\Field\FieldDefinitionInterface[] The attribute field definitions, keyed by field name.

Overrides ProductAttributeFieldManagerInterface::getFieldDefinitions

2 calls to ProductAttributeFieldManager::getFieldDefinitions()
ProductAttributeFieldManager::buildFieldMap in modules/product/src/ProductAttributeFieldManager.php
Builds the field map.
ProductAttributeFieldManager::getHighestWeight in modules/product/src/ProductAttributeFieldManager.php
Gets the highest weight of the attribute field components in the display.

File

modules/product/src/ProductAttributeFieldManager.php, line 83

Class

ProductAttributeFieldManager
Default implementation of the ProductAttributeFieldManagerInterface.

Namespace

Drupal\commerce_product

Code

public function getFieldDefinitions($variation_type_id) {
  if (!isset($this->fieldDefinitions[$variation_type_id])) {
    $definitions = $this->entityFieldManager
      ->getFieldDefinitions('commerce_product_variation', $variation_type_id);
    $definitions = array_filter($definitions, function ($definition) {

      /** @var \Drupal\Core\Field\FieldDefinitionInterface $definition */
      $field_type = $definition
        ->getType();
      $target_type = $definition
        ->getSetting('target_type');
      return $field_type == 'entity_reference' && $target_type == 'commerce_product_attribute_value';
    });
    $this->fieldDefinitions[$variation_type_id] = $definitions;
  }
  return $this->fieldDefinitions[$variation_type_id];
}