public function ConfigurableFieldManager::deleteField in Commerce Core 8.2
Deletes the configurable field created from the given field definition.
Parameters
\Drupal\entity\BundleFieldDefinition $field_definition: The field definition.
Throws
\InvalidArgumentException Thrown when given an incomplete field definition (missing name, target entity type ID, or target bundle).
\RuntimeException Thrown when no matching field was found.
Overrides ConfigurableFieldManagerInterface::deleteField
File
- src/
ConfigurableFieldManager.php, line 90
Class
Namespace
Drupal\commerceCode
public function deleteField(EntityBundleFieldDefinition $field_definition) {
$field_name = $field_definition
->getName();
$entity_type_id = $field_definition
->getTargetEntityTypeId();
$bundle = $field_definition
->getTargetBundle();
if (empty($field_name) || empty($entity_type_id) || empty($bundle)) {
throw new \InvalidArgumentException('The passed $field_definition is incomplete.');
}
$field = FieldConfig::loadByName($entity_type_id, $bundle, $field_name);
if (empty($field)) {
throw new \RuntimeException(sprintf('The field "%s" does not exist on bundle "%s" of entity type "%s".', $field_name, $bundle, $entity_type_id));
}
$field = FieldConfig::loadByName($entity_type_id, $bundle, $field_name);
$field
->delete();
}