You are here

function commerce_product_add_body_field in Commerce Core 8.2

Adds the default body field to a product type.

Parameters

\Drupal\commerce_product\Entity\ProductTypeInterface $product_type: The product type.

string $label: (optional) The label for the body instance. Defaults to 'Body'.

1 call to commerce_product_add_body_field()
ProductTypeForm::save in modules/product/src/Form/ProductTypeForm.php
Form submission handler for the 'save' action.

File

modules/product/commerce_product.module, line 211
Defines the Product entity and associated features.

Code

function commerce_product_add_body_field(ProductTypeInterface $product_type, $label = 'Body') {
  $field_definition = BundleFieldDefinition::create('text_with_summary')
    ->setTargetEntityTypeId('commerce_product')
    ->setTargetBundle($product_type
    ->id())
    ->setName('body')
    ->setLabel($label)
    ->setTranslatable(TRUE)
    ->setSetting('display_summary', FALSE)
    ->setDisplayOptions('form', [
    'type' => 'text_textarea_with_summary',
    'weight' => 1,
  ])
    ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'text_default',
  ]);
  $configurable_field_manager = \Drupal::service('commerce.configurable_field_manager');
  $configurable_field_manager
    ->createField($field_definition, FALSE);
}