commands-1.x-dev/modules/tasks/src/Entity/TaskType.php

modules/tasks/src/Entity/TaskType.php
<?php

declare(strict_types=1);

namespace Drupal\tasks\Entity;

use Drupal\commands\CommandPluginBase;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;

/**
 * Defines the Tasks type configuration entity.
 *
 * @ConfigEntityType(
 *   id = "task_type",
 *   label = @Translation("Task type"),
 *   label_collection = @Translation("Task types"),
 *   label_singular = @Translation("task type"),
 *   label_plural = @Translation("task types"),
 *   label_count = @PluralTranslation(
 *     singular = "@count task type",
 *     plural = "@count task types",
 *   ),
 *   handlers = {
 *     "form" = {
 *       "add" = "Drupal\tasks\Form\TaskTypeForm",
 *       "edit" = "Drupal\tasks\Form\TaskTypeForm",
 *       "delete" = "Drupal\Core\Entity\EntityDeleteForm",
 *     },
 *     "list_builder" = "Drupal\tasks\TaskTypeListBuilder",
 *     "route_provider" = {
 *       "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider",
 *     },
 *   },
 *   admin_permission = "administer task types",
 *   bundle_of = "task",
 *   config_prefix = "task_type",
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label",
 *     "description" = "description",
 *   },
 *   links = {
 *     "add-form" = "/admin/structure/task_types/add",
 *     "edit-form" = "/admin/structure/task_types/manage/{task_type}",
 *     "delete-form" = "/admin/structure/task_types/manage/{task_type}/delete",
 *     "collection" = "/admin/structure/task_types",
 *   },
 *   config_export = {
 *     "id",
 *     "label",
 *     "description",
 *   },
 * )
 */
final class TaskType extends ConfigEntityBundleBase {

  /**
   * The machine name of this tasks type.
   */
  protected string $id;

  /**
   * The human-readable name of the tasks type.
   */
  protected string $label;

  /**
   * Description of the task type.
   *
   * @var string|null
   */
  protected $description = NULL;

  /**
   * {@inheritdoc}
   */
  public function description() {
    return $this->description ?? '';
  }

  public function commands() {
  }

  /**
   * @var string
   */
  protected $task_plugin;

  /**
   * The command to run for commands of this type, with tokens.
   * @return CommandPluginBase
   */
  public function setPlugin($plugin_id) {
    $this->task_plugin = $plugin_id;
    return $this;
  }
  /**
   * The command to run for commands of this type, with tokens.
   * @return CommandPluginBase
   */
  public function getPlugin($options = []) {
    $plugin = \Drupal::service('plugin.manager.task_type')->createInstance($this->task_plugin ?: $this->id(), $options);
    return $plugin;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc