You are here

public function EntityTraitManager::canUninstallTrait in Commerce Core 8.2

Checks whether the given trait can be uninstalled.

A trait can only be uninstalled if the fields it provides contain no data.

Parameters

\Drupal\commerce\Plugin\Commerce\EntityTrait\EntityTraitInterface $trait: The trait.

string $entity_type_id: The entity type id.

string $bundle: The bundle.

Overrides EntityTraitManagerInterface::canUninstallTrait

File

src/EntityTraitManager.php, line 110

Class

EntityTraitManager
Manages discovery and instantiation of entity trait plugins.

Namespace

Drupal\commerce

Code

public function canUninstallTrait(EntityTraitInterface $trait, $entity_type_id, $bundle) {
  foreach ($trait
    ->buildFieldDefinitions() as $field_name => $field_definition) {
    $field_definition
      ->setTargetEntityTypeId($entity_type_id);
    $field_definition
      ->setTargetBundle($bundle);
    $field_definition
      ->setName($field_name);
    if ($this->configurableFieldManager
      ->hasData($field_definition)) {
      return FALSE;
    }
  }
  return TRUE;
}