Skip to content

Instantly share code, notes, and snippets.

@acrosman
Last active April 4, 2019 22:42
Show Gist options
  • Save acrosman/e5458193975e1a6fd5fd1c480caf88f2 to your computer and use it in GitHub Desktop.
Save acrosman/e5458193975e1a6fd5fd1c480caf88f2 to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\sitemanager\Plugin;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Config\ConfigFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\sitemanager\SimpleProcess;
use Drupal\sitemanager\Entity\Site;
/**
* Base class for Task plugin plugins.
*/
abstract class TaskPluginBase extends PluginBase implements TaskPluginInterface, ContainerFactoryPluginInterface {
use StringTranslationTrait;
protected $processService;
protected $config;
protected $output;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration,
$plugin_id,
$plugin_definition,
SimpleProcess $simple_process,
TranslationInterface $string_translation,
ConfigFactory $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->processService = $simple_process;
$this->stringTranslation = $string_translation;
$this->config = $config_factory->get('sitemanager.sitemanagersettings');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container,
array $configuration,
$plugin_id,
$plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('cw_sitemanager.simple_process'),
$container->get('string_translation'),
$container->get('config.factory')
);
}
/**
* Return the name of the task.
*
* @return string
* returns the name as a string.
*/
public function getTaskName() {
return $this->pluginDefinition['taskName'];
}
/**
* Returns the status of the task defined by this plugin.
*
* @return string
* Returns: "Success" or "Error".
*/
public function getTaskStatus() {
return $this->pluginDefinition['status'];
}
/**
* Returns the output of the task as a renderable array.
*
* @return array
* Returns a render array of the message to be embedded in a table.
*/
public function getTaskOutput() {
return $this->output;
}
/**
* Runs the task (is the definition of the task).
*
* @param Site $site
* The site entity to be used.
*
* @return string
* Returns: getTaskStatus();
*/
abstract public function run(Site $site);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment