class DurationFieldCommand in Duration Field 8.2
Same name and namespace in other branches
- 3.0.x src/Drush/DurationFieldCommand.php \Drupal\duration_field\Drush\DurationFieldCommand
Drush commands for the Duration Field module.
Hierarchy
- class \Drupal\duration_field\Drush\DurationFieldCommand extends \Drush\Commands\DrushCommands
Expanded class hierarchy of DurationFieldCommand
1 string reference to 'DurationFieldCommand'
1 service uses DurationFieldCommand
File
- src/
Drush/ DurationFieldCommand.php, line 15
Namespace
Drupal\duration_field\DrushView source
class DurationFieldCommand extends DrushCommands {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Constructs a DurationFieldCommand object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo
* The entity type bundle info service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* The entity field manager.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, EntityTypeBundleInfoInterface $entityTypeBundleInfo, EntityFieldManagerInterface $entityFieldManager) {
$this->entityTypeManager = $entityTypeManager;
$this->entityTypeBundleInfo = $entityTypeBundleInfo;
$this->entityFieldManager = $entityFieldManager;
}
/**
* Prepares the Duration Field module for uninstall.
*
* Deletes all data and field instances.
*
* @command duration_field:prepare_uninstall
* @aliases df-pu
* @usage duration_field:prepare_uninstall
* Deletes all duration field data and duration field fields from the
* system.
*/
public function prepareModuleUninstall() {
if ($this
->confirm('This will delete all duration field in the database, with no means to retrieve it. Do you wish to continue?')) {
$this
->output()
->writeln("The following fields have been deleted:");
$fields = duration_field_get_duration_fields();
foreach ($fields as $field) {
$this->output
->writeln($field['entity_type'] . ':' . $field['bundle'] . ':' . $field['field']
->getName());
// Delete field.
$config = FieldConfig::loadByName($field['entity_type'], $field['bundle'], $field['field']
->getName());
if ($config) {
$config
->delete();
}
// Delete field storage.
$storage = FieldStorageConfig::loadByName($field['entity_type'], $field['field']
->getName());
if ($storage) {
$storage
->delete();
}
}
}
else {
$this
->output()
->writeln("No loss of duration for you");
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DurationFieldCommand:: |
protected | property | The entity field manager. | |
DurationFieldCommand:: |
protected | property | The entity type bundle info service. | |
DurationFieldCommand:: |
protected | property | The entity type manager. | |
DurationFieldCommand:: |
public | function | Prepares the Duration Field module for uninstall. | |
DurationFieldCommand:: |
public | function | Constructs a DurationFieldCommand object. |