commands-1.x-dev/src/Entity/CommandType.php
src/Entity/CommandType.php
<?php
namespace Drupal\commands\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\commands\CommandPluginBase;
/**
* Defines the Command type configuration entity.
*
* @ConfigEntityType(
* id = "command_type",
* label = @Translation("Command type"),
* label_collection = @Translation("Command types"),
* label_singular = @Translation("command type"),
* label_plural = @Translation("Command types"),
* label_count = @PluralTranslation(
* singular = "@count command type",
* plural = "@count commands types",
* ),
* handlers = {
* "form" = {
* "add" = "Drupal\commands\Form\CommandTypeForm",
* "edit" = "Drupal\commands\Form\CommandTypeForm",
* "delete" = "Drupal\Core\Entity\EntityDeleteForm",
* },
* "list_builder" = "Drupal\commands\CommandTypeListBuilder",
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider",
* }
* },
* admin_permission = "administer command types",
* bundle_of = "command",
* config_prefix = "command_type",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "description" = "description",
* },
* links = {
* "add-form" = "/admin/structure/command_types/add",
* "edit-form" = "/admin/structure/command_types/manage/{command_type}",
* "delete-form" = "/admin/structure/command_types/manage/{command_type}/delete",
* "collection" = "/admin/structure/command_types"
* },
* config_export = {
* "id",
* "label",
* "description",
* "command_plugin",
* }
* )
*/
class CommandType extends ConfigEntityBundleBase {
/**
* The machine name of this command type.
*
* @var string
*/
protected $id;
/**
* The human-readable name of the command type.
*
* @var string
*/
protected $label;
/**
* Description of the command type.
*
* @var string|null
*/
protected $description = NULL;
/**
* {@inheritdoc}
*/
public function description() {
return $this->description ?? '';
}
/**
* @var string
*/
protected $command_plugin;
/**
* The command to run for commands of this type, with tokens.
* @return CommandPluginBase
*/
public function commandPlugin($options = []) {
return \Drupal::service('plugin.manager.commands')->createInstance($this->command_plugin, $options);
}
}
