You are here

public function CommerceAutoSkuManager::hasSku in Commerce AutoSKU 8.2

Checks if the entity has a label.

Return value

bool True if the entity has a label property.

2 calls to CommerceAutoSkuManager::hasSku()
CommerceAutoSkuManager::getSkuName in src/CommerceAutoSkuManager.php
Gets the field name of the entity label.
CommerceAutoSkuManager::setSku in src/CommerceAutoSkuManager.php
Sets the automatically generated entity label.

File

src/CommerceAutoSkuManager.php, line 113
Contains \Drupal\commerce_autosku\AutoEntityLabelManager.

Class

CommerceAutoSkuManager

Namespace

Drupal\commerce_autosku

Code

public function hasSku() {

  /** @var \Drupal\Core\Entity\EntityTypeInterface $definition */
  $definition = $this->entityTypeManager
    ->getDefinition($this->entity
    ->getEntityTypeId());

  // @todo cleanup.
  $hasKey = $definition
    ->hasKey('sku');
  if ($hasKey) {
    return $hasKey;
  }
  $entityManager = \Drupal::service('entity_field.manager');
  $fields = $entityManager
    ->getFieldDefinitions($this->entity
    ->getEntityTypeId(), $this->entity
    ->bundle());
  if (isset($fields['sku'])) {
    return TRUE;
  }
}