You are here

public function ProductAttributeFieldManager::deleteField in Commerce Core 8.2

Deletes the attribute field for the given attribute.

Parameters

\Drupal\commerce_product\Entity\ProductAttributeInterface $attribute: The product attribute.

string $variation_type_id: The product variation type ID.

Overrides ProductAttributeFieldManagerInterface::deleteField

File

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

Class

ProductAttributeFieldManager
Default implementation of the ProductAttributeFieldManagerInterface.

Namespace

Drupal\commerce_product

Code

public function deleteField(ProductAttributeInterface $attribute, $variation_type_id) {
  if (!$this
    ->canDeleteField($attribute, $variation_type_id)) {
    return;
  }
  $field_name = $this
    ->buildFieldName($attribute);
  $field = FieldConfig::loadByName('commerce_product_variation', $variation_type_id, $field_name);
  if ($field) {
    $field
      ->delete();
    $this
      ->clearCaches();
  }
}