You are here

function dc_ajax_add_cart_entity_bundle_create in Commerce Ajax Add to Cart 8

Implements hook_entity_bundle_create().

Creates an 'dc_ajax_add_cart' form display for each new order item type.

File

./dc_ajax_add_cart.module, line 18
Ajax add to cart module.

Code

function dc_ajax_add_cart_entity_bundle_create($entity_type_id, $bundle) {
  if ($entity_type_id == 'commerce_order_item' && !\Drupal::isConfigSyncing()) {
    $storage = \Drupal::service('entity_type.manager')
      ->getStorage('entity_form_display');
    $form_display = $storage
      ->load('commerce_order_item.' . $bundle . '.dc_ajax_add_cart');
    if (!$form_display) {

      /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
      $form_display = $storage
        ->create([
        'targetEntityType' => 'commerce_order_item',
        'bundle' => $bundle,
        'mode' => 'dc_ajax_add_cart',
        'status' => TRUE,
      ]);
      $form_display
        ->save();
    }
  }
}