Skip to content
Snippets Groups Projects
Commit a02f414f authored by Mohammad AbulQader's avatar Mohammad AbulQader
Browse files

Issue #3490936: Fix PHPCS issues

parent ec0696d6
No related branches found
No related tags found
No related merge requests found
......@@ -104,84 +104,84 @@ class TicketController extends ControllerBase implements ContainerInjectionInter
foreach (array_reverse($vids) as $vid) {
/** @var \Drupal\tms\TicketInterface $revision */
$revision = $ticket_storage->loadRevision($vid);
$username = [
'#theme' => 'username',
'#account' => $revision->getRevisionUser(),
];
// Use revision link to link to revisions that are not active.
$date = $this->dateFormatter->format($revision->getRevisionCreationTime(), 'short');
if ($vid != $ticket->getRevisionId()) {
$link = Link::fromTextAndUrl($date, new Url('entity.ticket.revision', [
'ticket' => $ticket->id(),
'ticket_revision' => $vid,
]));
}
else {
$link = $ticket->toLink($date);
}
$username = [
'#theme' => 'username',
'#account' => $revision->getRevisionUser(),
];
// Use revision link to link to revisions that are not active.
$date = $this->dateFormatter->format($revision->getRevisionCreationTime(), 'short');
if ($vid != $ticket->getRevisionId()) {
$link = Link::fromTextAndUrl($date, new Url('entity.ticket.revision', [
'ticket' => $ticket->id(),
'ticket_revision' => $vid,
]));
}
else {
$link = $ticket->toLink($date);
}
$row = [];
$column = [
'data' => [
'#type' => 'inline_template',
'#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}',
'#context' => [
'date' => $date,
'username' => $this->renderer->renderPlain($username),
'message' => [
'#markup' => $revision->getRevisionLogMessage(),
'#allowed_tags' => Xss::getHtmlTagList(),
],
],
],
];
$row[] = $column;
$row = [];
$column = [
if ($latest_revision) {
$row[] = [
'data' => [
'#type' => 'inline_template',
'#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}',
'#context' => [
'date' => $date,
'username' => $this->renderer->renderPlain($username),
'message' => [
'#markup' => $revision->getRevisionLogMessage(),
'#allowed_tags' => Xss::getHtmlTagList(),
],
],
'#prefix' => '<em>',
'#markup' => $this->t('Current revision'),
'#suffix' => '</em>',
],
];
$row[] = $column;
if ($latest_revision) {
$row[] = [
'data' => [
'#prefix' => '<em>',
'#markup' => $this->t('Current revision'),
'#suffix' => '</em>',
],
foreach ($row as &$current) {
$current['class'] = ['revision-current'];
}
$latest_revision = FALSE;
}
else {
$links = [];
if ($revert_permission) {
$links['revert'] = [
'title' => $this->t('Revert'),
'url' => Url::fromRoute('entity.ticket.revision_revert', [
'ticket' => $ticket->id(),
'ticket_revision' => $vid,
]),
];
foreach ($row as &$current) {
$current['class'] = ['revision-current'];
}
$latest_revision = FALSE;
}
else {
$links = [];
if ($revert_permission) {
$links['revert'] = [
'title' => $this->t('Revert'),
'url' => Url::fromRoute('entity.ticket.revision_revert', [
'ticket' => $ticket->id(),
'ticket_revision' => $vid,
]),
];
}
if ($delete_permission) {
$links['delete'] = [
'title' => $this->t('Delete'),
'url' => Url::fromRoute('entity.ticket.revision_delete', [
'ticket' => $ticket->id(),
'ticket_revision' => $vid,
]),
];
}
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
if ($delete_permission) {
$links['delete'] = [
'title' => $this->t('Delete'),
'url' => Url::fromRoute('entity.ticket.revision_delete', [
'ticket' => $ticket->id(),
'ticket_revision' => $vid,
]),
];
}
$rows[] = $row;
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
}
$rows[] = $row;
}
$build['ticket_revisions_table'] = [
......
......@@ -58,7 +58,7 @@ use Drupal\user\UserInterface;
* "revision_user" = "revision_user",
* "revision_created" = "revision_created",
* "revision_log_message" = "revision_log_message",
* },
* },
* links = {
* "canonical" = "/admin/content/tickets/{ticket}",
* "add-page" = "/admin/content/tickets/add",
......@@ -222,23 +222,24 @@ class Ticket extends EditorialContentEntityBase implements TicketInterface {
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['users'] = BaseFieldDefinition::create('entity_reference')
$fields['users'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Assigne To Users'))
->setDescription(t('Assigned To Users with a ( custom ) Role'))
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDisplayOptions('view', array(
->setSetting('handler', 'default')
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'user',
'weight' => -4,
))
->setSetting('handler_settings',[
])
->setSetting('handler_settings', [
'filter' => [
'type' => 'role',
'role'=>[
'customer' => 'customer'
]
]])
'type' => 'role',
'role' => [
'customer' => 'customer',
],
],
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => -4,
......@@ -253,25 +254,26 @@ class Ticket extends EditorialContentEntityBase implements TicketInterface {
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayConfigurable('view', TRUE);
$fields['priority'] = BaseFieldDefinition::create('entity_reference')
$fields['priority'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Priority'))
->setSetting('target_type', 'taxonomy_term')
->setSetting('handler', 'default:taxonomy_term')
->setSetting('handler_settings',[
'target_bundles' => [
'priority' => 'priority'
]])
->setDisplayOptions('view', array(
->setSetting('handler_settings', [
'target_bundles' => [
'priority' => 'priority',
],
])
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'options_select',
'weight' => -4,
))
->setDisplayOptions('form', array(
])
->setDisplayOptions('form', [
'type' => 'options_select',
'weight' => -4,
))
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
->setDisplayConfigurable('view', TRUE);
$fields['status']->setDescription(t('A boolean indicating whether the Ticket is published.'))
->setDisplayOptions('form', [
......
......@@ -33,7 +33,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
* config_export = {
* "id",
* "label",
* },
* },
* links = {
* "canonical" = "/admin/structure/ticket_type/{ticket_type}",
* "add-form" = "/admin/structure/ticket_type/add",
......
......@@ -16,11 +16,11 @@ class TicketViewsData extends EntityViewsData {
$data = parent::getViewsData();
$data_table = $this->entityType->getDataTable();
$fields = &$data['ticket'];
foreach($fields as &$field) {
if(isset($field['filter']) && isset($field['relationship']) && $field['relationship']['base'] === 'taxonomy_term_field_data') {
foreach ($fields as &$field) {
if (isset($field['filter']) && isset($field['relationship']) && $field['relationship']['base'] === 'taxonomy_term_field_data') {
$field['filter']['id'] = 'taxonomy_index_tid';
}
}
}
return $data;
}
......
......@@ -34,7 +34,7 @@ class TicketForm extends ContentEntityForm {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var \Drupal\tms\Entity\Ticket $entity */
/** @var \Drupal\tms\Entity\Ticket $entity */
$form = parent::buildForm($form, $form_state);
if (!$this->entity->isNew()) {
......
......@@ -6,8 +6,6 @@ use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\tms\Entity\Ticket;
use Drupal\tms\Entity\TicketType;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -19,7 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* category = @Translation("Ticket Form Block"),
* )
*/
class TicketBlock extends BlockBase implements ContainerFactoryPluginInterface {
class TicketBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
......@@ -28,29 +26,27 @@ class TicketBlock extends BlockBase implements ContainerFactoryPluginInterface
protected $entityTypeManager;
/**
* Constructs a new TicketBlock
* Constructs a new TicketBlock.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager)
{
parent::__construct($configuration, $plugin_id,$plugin_definition);
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritDoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
{
return new static(
$configuration, $plugin_id,$plugin_definition, $container->get('entity_type.manager')
);
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager')
);
}
/**
/**
* Overrides \Drupal\block\BlockBase::blockForm().
*/
public function blockForm($form, FormStateInterface $form_state) {
$form['formblock_ticket_type'] = [
'#title' => $this->t('Ticket type'),
'#description' => $this->t('Select the Ticket type whose form will be shown in the block.'),
......@@ -58,7 +54,7 @@ class TicketBlock extends BlockBase implements ContainerFactoryPluginInterface
'#required' => TRUE,
'#options' => $this->getTicketTypes(),
'#default_value' => $this->configuration['type'],
];
];
return $form;
}
......@@ -87,13 +83,13 @@ class TicketBlock extends BlockBase implements ContainerFactoryPluginInterface
/**
* {@inheritdoc}
*/
*/
public function build() {
/** @var \Drupal\tms\Entity\TicketInterface $entity */
$entity = $this->entityTypeManager->getStorage('ticket')->create([
'type' => $this->configuration['type'],
]);
return \Drupal::service('entity.form_builder')->getForm($entity,'default');
return \Drupal::service('entity.form_builder')->getForm($entity, 'default');
}
}
\ No newline at end of file
}
......@@ -5,14 +5,12 @@ namespace Drupal\tms;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\tms\Entity\Ticket;
/**
* Provides dynamic permissions for Ticket of different types.
*
* @ingroup tms
*
*/
class TicketPermissions{
class TicketPermissions {
use StringTranslationTrait;
......
<?php
/**
* @file
*/
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
......@@ -9,36 +12,35 @@ use Drupal\user\Entity\Role;
* Add some terms to the Category vocabulary.
*/
function tms_install() {
// Add Priority Terms
// Add Priority Terms.
$vid = "priority";
$vocabularies = Vocabulary::loadMultiple();
if (isset($vocabularies[$vid])) {
$categories = ['Hight', 'Low', 'Medium']; // List of Status terms
// List of Status terms.
$categories = ['Hight', 'Low', 'Medium'];
foreach ($categories as $category) {
$term = Term::create(array(
'parent' => array(),
$term = Term::create([
'parent' => [],
'name' => $category,
'vid' => $vid,
))->save();
'vid' => $vid,
])->save();
}
}
// Add Role
$role = Role::loadMultiple();
if (!isset($role['customer'])) {
Role::create([
'id' => 'customer',
'permissions' => ['add ticket entities'],
'label' => 'customer',
])->save();
}
if (!isset($role['agent'])) {
Role::create([
'id' => 'agent',
'permissions' => ['administer ticket entities'],
'label' => 'Agent',
])->save();
}
// Add Role.
$role = Role::loadMultiple();
if (!isset($role['customer'])) {
Role::create([
'id' => 'customer',
'permissions' => ['add ticket entities'],
'label' => 'customer',
])->save();
}
if (!isset($role['agent'])) {
Role::create([
'id' => 'agent',
'permissions' => ['administer ticket entities'],
'label' => 'Agent',
])->save();
}
}
......@@ -12,4 +12,4 @@ entity.ticket_type.collection:
route_name: entity.ticket_type.collection
description: 'List ticket entity type (bundles)'
parent: system.admin_structure
weight: 99
\ No newline at end of file
weight: 99
<?php
/**
* Implements hook_entity_form_display_alter().
* @file
* Implements hook_entity_form_display_alter().
*/
function tms_entity_form_display_alter(\Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display, array $context) {
if($context["entity_type"]=='ticket'){
if(!\Drupal::currentUser()->hasPermission('View all Ticket revisions')){
$form_display->removeComponent('revision_log_message');
}
use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
/**
*
*/
function tms_entity_form_display_alter(EntityFormDisplayInterface $form_display, array $context) {
if ($context["entity_type"] == 'ticket') {
if (!\Drupal::currentUser()->hasPermission('View all Ticket revisions')) {
$form_display->removeComponent('revision_log_message');
}
}
\ No newline at end of file
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment