You are here

dc_ajax_add_cart.install in Commerce Ajax Add to Cart 8

Same filename and directory in other branches
  1. 7.2 dc_ajax_add_cart.install
  2. 7 dc_ajax_add_cart.install

Install/uninstall actions for dc_ajax_add_cart module.

File

dc_ajax_add_cart.install
View source
<?php

/**
 * @file
 * Install/uninstall actions for dc_ajax_add_cart module.
 */

/**
 * Implements hook_install().
 */
function dc_ajax_add_cart_install() {

  /*
   * Create 'dc_ajax_add_cart' form display for existing order item types.
   */
  if (!\Drupal::isConfigSyncing()) {
    $order_item_type_bundles = \Drupal::service('entity_type.bundle.info')
      ->getBundleInfo('commerce_order_item');
    $storage = \Drupal::service('entity_type.manager')
      ->getStorage('entity_form_display');
    foreach (array_keys($order_item_type_bundles) as $bundle) {
      $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();
      }
    }
  }
}

Functions

Namesort descending Description
dc_ajax_add_cart_install Implements hook_install().