You are here

protected function ContentEntity::getLangcodeKey in Commerce Core 8.2

Gets the langcode key for the given entity.

Ensures that the key is not empty, which is allowed by Drupal even if the entity itself is translatable.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.

Return value

string The langcode key.

Throws

\RuntimeException Thrown when the entity type does not have a langcode key defined.

2 calls to ContentEntity::getLangcodeKey()
ContentEntity::ensureTranslation in src/Plugin/Commerce/InlineForm/ContentEntity.php
Ensures the correct entity translation.
ContentEntity::updateLangcode in src/Plugin/Commerce/InlineForm/ContentEntity.php
Updates the entity langcode to match the form langcode.

File

src/Plugin/Commerce/InlineForm/ContentEntity.php, line 204

Class

ContentEntity
Provides an inline form for managing a content entity.

Namespace

Drupal\commerce\Plugin\Commerce\InlineForm

Code

protected function getLangcodeKey(ContentEntityInterface $entity) {
  $entity_type = $entity
    ->getEntityType();
  $langcode_key = $entity_type
    ->getKey('langcode');
  if (empty($langcode_key)) {
    throw new \RuntimeException(sprintf('The entity type %s did not specify a langcode key.', $entity_type
      ->id()));
  }
  return $langcode_key;
}