Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
attus74 committed Jul 6, 2023
1 parent a1b0571 commit f5af0c0
Show file tree
Hide file tree
Showing 11 changed files with 1,529 additions and 84 deletions.
40 changes: 39 additions & 1 deletion devutil.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,42 @@ services:
devutil.commands:
class: \Drupal\devutil\Commands\Commands
tags:
- { name: drush.command }
- { name: drush.command }
arguments:
- '@devutil.manager.plugin'
- '@devutil.manager.config'
- '@devutil.manager.content'
- '@devutil.manager.bundle'
devutil.manager.plugin:
class: \Drupal\devutil\PluginManager
arguments:
- '@extension.list.module'
- '@file_system'
- '@module_handler'
devutil.manager.config:
class: \Drupal\devutil\ConfigEntityManager
arguments:
- '@logger.factory'
- '@file_system'
- '@module_handler'
- '@extension.list.module'
- '@entity_type.manager'
- '@entity_type.bundle.info'
devutil.manager.content:
class: \Drupal\devutil\ContentEntityManager
arguments:
- '@logger.factory'
- '@file_system'
- '@module_handler'
- '@extension.list.module'
- '@entity_type.manager'
- '@entity_type.bundle.info'
devutil.manager.bundle:
class: \Drupal\devutil\EntityBundleManager
arguments:
- '@logger.factory'
- '@file_system'
- '@module_handler'
- '@extension.list.module'
- '@entity_type.manager'
- '@entity_type.bundle.info'
42 changes: 25 additions & 17 deletions src/Commands/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use Drush\Commands\DrushCommands;
use Drupal\devutil\EntityManager;
use Drupal\devutil\ConfigEntityManager;
use Drupal\devutil\PluginManager;
use Drupal\devutil\EntityManagerInterface;
use Drupal\devutil\EntityBundleManager;
use Drupal\devutil\PluginManagerInterface;
use Drupal\devutil\EntityBundleManagerInterface;

/**
* Drush Commands
Expand All @@ -16,6 +17,21 @@
*/
class Commands extends DrushCommands {

private $_pluginManager;
private $_configEntitymanager;
private $_contentEntityManager;
private $_entityBundleManager;

public function __construct(PluginManagerInterface $pluginManager,
EntityManagerInterface $configEntityManager,
EntityManagerInterface $contentEntityManager,
EntityBundleManagerInterface $entityBundleManager) {
$this->_pluginManager = $pluginManager;
$this->_configEntitymanager = $configEntityManager;
$this->_contentEntityManager = $contentEntityManager;
$this->_entityBundleManager = $entityBundleManager;
}

/**
* Creates a custom Content Entity Type
*
Expand All @@ -38,16 +54,9 @@ public function contentEntity(string $machineName, string $label, array $options
throw new \Exception('Path may only be used if a new module shall be created');
}
if ($options['bundle-classes'] && !$options['bundles']) {
throw new \Exceltipn('Bundle classes may only be created if the entity type has bundles');
}
$manager = new EntityManager();
if ($options['module'] == '') {
$moduleName = $machineName;
}
else {
$moduleName = $options['module'];
throw new \Exception('Bundle classes may only be created if the entity type has bundles');
}
$manager->create($machineName, $label, $options['bundles'], $moduleName, $options);
$this->_contentEntityManager->createCode($machineName, $label, $options);
echo "Your code is created\n";
}

Expand All @@ -67,8 +76,9 @@ public function contentEntityBundle(string $entityTypeId, string $bundleId, stri
'name' => null,
]): void
{
$manager = new EntityBundleManager($entityTypeId);
$manager->createBundle($bundleId, $bundleLabel, $options);
$manager = $this->_entityBundleManager;
$manager->setEntityType($entityTypeId);
$manager->createCode($bundleId, $bundleLabel, $options);
}

/**
Expand All @@ -89,8 +99,7 @@ public function configEntity(string $machineName, string $label, array $options
if (!empty($options['module']) && !empty($options['path'])) {
throw new \Exception('Path may only be used if a new module shall be created');
}
$manager = new ConfigEntityManager();
$manager->createCode($machineName, $label, $options);
$this->_configEntitymanager->createCode($machineName, $label, $options);
}

/**
Expand All @@ -106,11 +115,10 @@ public function plugin(string $name, array $options = [
'name' => '',
]): void
{
$manager = new PluginManager();
if ($options['module'] == '') {
$options['module'] = $name;
}
$manager->create($name, $options['module'], $options['name']);
$this->_pluginManager->create($name, $options['module'], $options['name']);
}

}
2 changes: 1 addition & 1 deletion src/ConfigEntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function _createEntityClasses(): void
protected function _createSchema(): void
{
$schemaDir = $this->_modulePath . '/config/schema';
\Drupal::service('file_system')->prepareDirectory($schemaDir, FileSystemInterface::MODIFY_PERMISSIONS | FileSystemInterface::CREATE_DIRECTORY);
$this->_fileSystem->prepareDirectory($schemaDir, FileSystemInterface::MODIFY_PERMISSIONS | FileSystemInterface::CREATE_DIRECTORY);
$schema = [
$this->_entityTypeName . '.' . $this->_entityTypeName => [
'type' => 'config_entity',
Expand Down

0 comments on commit f5af0c0

Please sign in to comment.