View source
<?php
namespace Drupal\queue_ui\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\queue_ui\QueueUIManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ItemDetailForm extends FormBase {
private $queueUIManager;
public function __construct(QueueUIManager $queueUIManager) {
$this->queueUIManager = $queueUIManager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.queue_ui'));
}
public function getFormId() {
return 'queue_ui_item_detail_form';
}
public function buildForm(array $form, FormStateInterface $form_state, $queue_name = FALSE, $queue_item = FALSE) {
if ($queue_ui = $this->queueUIManager
->fromQueueName($queue_name)) {
$queue_item = $queue_ui
->loadItem($queue_item);
$data = [
'#type' => 'html_tag',
'#tag' => 'pre',
'#value' => print_r(unserialize($queue_item->data), TRUE),
];
$data = \Drupal::service('renderer')
->renderPlain($data);
if (\Drupal::service('module_handler')
->moduleExists('devel')) {
$data = kpr(unserialize($queue_item->data), TRUE);
}
$rows = [
'id' => [
'data' => [
'header' => $this
->t('Item ID'),
'data' => $queue_item->item_id,
],
],
'queue_name' => [
'data' => [
'header' => $this
->t('Queue name'),
'data' => $queue_item->name,
],
],
'expire' => [
'data' => [
'header' => $this
->t('Expire'),
'data' => $queue_item->expire ? date(DATE_RSS, $queue_item->expire) : $queue_item->expire,
],
],
'created' => [
'data' => [
'header' => $this
->t('Created'),
'data' => date(DATE_RSS, $queue_item->created),
],
],
'data' => [
'data' => [
'header' => [
'data' => $this
->t('Data'),
'style' => 'vertical-align:top',
],
'data' => $data,
],
],
];
return [
'table' => [
'#type' => 'table',
'#rows' => $rows,
],
];
}
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}