SendContextAction.php in TMGMT Translator Smartling 8.2
Same filename and directory in other branches
Contains \Drupal\smartling\Plugin\Action\TranslateNode.
Namespace
Drupal\tmgmt_smartling\Plugin\ActionFile
src/Plugin/Action/SendContextAction.phpView source
<?php
/**
* @file
* Contains \Drupal\smartling\Plugin\Action\TranslateNode.
*/
namespace Drupal\tmgmt_smartling\Plugin\Action;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Queue\QueueInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\PrivateTempStoreFactory;
/**
* Translate entity.
*
* @Action(
* id = "tmgmt_smartling_send_context_action",
* label = @Translation("Send context"),
* type = "tmgmt_job_item",
* confirm_form_route_name = "tmgmt_smartling.send_context_action"
* )
*/
class SendContextAction extends ActionBase implements ContainerFactoryPluginInterface {
/**
* The tempstore factory.
*
* @var \Drupal\user\PrivateTempStoreFactory
*/
protected $tempStoreFactory;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Creates TranslateNode action.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
* The tempstore factory.
* @param \Drupal\Core\Session\AccountInterface $current_user
* Current user.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $current_user;
$this->tempStoreFactory = $temp_store_factory;
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
if (!$account) {
return FALSE;
}
return $account
->hasPermission('send context smartling');
}
protected function getTempStoreName($entity_type = '') {
return 'tmgmt_smartling_send_context';
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('user.private_tempstore'), $container
->get('current_user'));
}
/**
* {@inheritdoc}
*/
public function executeMultiple(array $entities) {
$ids = [];
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
foreach ($entities as $entity) {
$ids[$entity
->id()] = $entity
->getEntityTypeId();
}
$entity = reset($entities);
if ($entity instanceof EntityInterface) {
$entity_type = $entity
->getEntityTypeId();
}
$this->tempStoreFactory
->get($this
->getTempStoreName($entity_type))
->set($this->currentUser
->id(), $ids);
}
/**
* {@inheritdoc}
*/
public function execute(ContentEntityInterface $entity = NULL) {
$this
->executeMultiple([
$entity,
]);
}
}
Classes
Name | Description |
---|---|
SendContextAction | Translate entity. |