You are here

function commerce_get_entity_display in Commerce Core 8.2

Gets the entity display for the given entity type and bundle.

The entity display will be created if missing.

Parameters

string $entity_type: The entity type.

string $bundle: The bundle.

string $display_context: The display context ('view' or 'form').

Return value

\Drupal\Core\Entity\Display\EntityDisplayInterface The entity display.

Throws

\InvalidArgumentException Thrown when an invalid display context is provided.

31 calls to commerce_get_entity_display()
AddToCartMultiAttributeTest::setUp in modules/cart/tests/src/FunctionalJavascript/AddToCartMultiAttributeTest.php
CheckoutOrderTest::testLoginWithRequiredRegistrationField in modules/checkout/tests/src/Functional/CheckoutOrderTest.php
Tests that login works even if the registration form has a required field.
CheckoutOrderTest::testRegisterOrderCheckoutWithCustomUserFields in modules/checkout/tests/src/Functional/CheckoutOrderTest.php
Tests that you can register from the checkout pane with custom user fields.
CheckoutOrderTest::testRegistrationAfterGuestOrderCheckoutWithCustomUserFields in modules/checkout/tests/src/Functional/CheckoutOrderTest.php
Tests custom user fields are respected on registration after checkout.
commerce_product_post_update_7 in modules/product/commerce_product.post_update.php
Move the variations form to its own tab.

... See full list

File

./commerce.module, line 164
Defines common functionality for all Commerce modules.

Code

function commerce_get_entity_display($entity_type, $bundle, $display_context) {
  if (!in_array($display_context, [
    'view',
    'form',
  ])) {
    throw new \InvalidArgumentException(sprintf('Invalid display_context %s passed to _commerce_product_get_display().', $display_context));
  }
  $storage = \Drupal::entityTypeManager()
    ->getStorage('entity_' . $display_context . '_display');
  $display = $storage
    ->load($entity_type . '.' . $bundle . '.default');
  if (!$display) {
    $display = $storage
      ->create([
      'targetEntityType' => $entity_type,
      'bundle' => $bundle,
      'mode' => 'default',
      'status' => TRUE,
    ]);
  }
  return $display;
}