You are here

function commerce_product_bundle_add_body_field in Commerce Product Bundle 8

Adds the default body field to a product bundle type.

Parameters

\Drupal\commerce_product_bundle\Entity\BundleTypeInterface $product_bundle_type: The product bundle type.

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

1 call to commerce_product_bundle_add_body_field()
ProductBundleTypeForm::save in src/Form/ProductBundleTypeForm.php
Form submission handler for the 'save' action.

File

./commerce_product_bundle.module, line 124
Contains commerce_product_bundle.module.

Code

function commerce_product_bundle_add_body_field(BundleTypeInterface $product_bundle_type, $label = 'Body') {
  $field_definition = BundleFieldDefinition::create('text_with_summary')
    ->setTargetEntityTypeId('commerce_product_bundle')
    ->setTargetBundle($product_bundle_type
    ->id())
    ->setName('body')
    ->setLabel($label)
    ->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);
}