Example #1
0
 /**
  * Override the behavior of title(). Get the title of the support ticket.
  */
 public function titleQuery()
 {
     $titles = array();
     $support_tickets = $this->supportTicketStorage->loadMultiple($this->value);
     foreach ($support_tickets as $support_ticket) {
         $titles[] = SafeMarkup::checkPlain($support_ticket->label());
     }
     return $titles;
 }
Example #2
0
 public function preRender($values)
 {
     $stids = array();
     foreach ($values as $row) {
         $stids[] = $row->{$this->field_alias};
     }
     if (!empty($stids)) {
         $this->support_tickets = $this->supportTicketStorage->loadMultiple($stids);
     }
 }
Example #3
0
 /**
  * Override the behavior of title(). Get the title of the revision.
  */
 public function titleQuery()
 {
     $titles = array();
     $results = $this->database->query('SELECT nr.vid, nr.stid, npr.title FROM {support_ticket_revision} nr WHERE nr.vid IN ( :vids[] )', array(':vids[]' => $this->value))->fetchAllAssoc('vid', PDO::FETCH_ASSOC);
     $stids = array();
     foreach ($results as $result) {
         $stids[] = $result['stid'];
     }
     $support_tickets = $this->supportTicketStorage->loadMultiple(array_unique($stids));
     foreach ($results as $result) {
         $support_tickets[$result['stid']]->set('title', $result['title']);
         $titles[] = SafeMarkup::checkPlain($support_tickets[$result['stid']]->label());
     }
     return $titles;
 }
 /**
  * Checks support_ticket revision access.
  *
  * @param \Drupal\support_ticket\SupportTicketInterface $support_ticket
  *   The support_ticket to check.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   A user object representing the user for whom the operation is to be
  *   performed.
  * @param string $op
  *   (optional) The specific operation being checked. Defaults to 'view.'
  *
  * @return bool
  *   TRUE if the operation may be performed, FALSE otherwise.
  */
 public function checkAccess(SupportTicketInterface $support_ticket, AccountInterface $account, $op = 'view')
 {
     $map = array('view' => 'view all revisions', 'update' => 'revert all revisions', 'delete' => 'delete all revisions');
     $bundle = $support_ticket->bundle();
     $type_map = array('view' => "view {$bundle} revisions", 'update' => "revert {$bundle} revisions", 'delete' => "delete {$bundle} revisions");
     if (!$support_ticket || !isset($map[$op]) || !isset($type_map[$op])) {
         // If there was no support_ticket to check against, or the $op was not one of
         // the supported ones, we return access denied.
         return FALSE;
     }
     // Statically cache access by revision ID, language code, user account ID,
     // and operation.
     $langcode = $support_ticket->language()->getId();
     $cid = $support_ticket->getRevisionId() . ':' . $langcode . ':' . $account->id() . ':' . $op;
     if (!isset($this->access[$cid])) {
         // Perform basic permission checks first.
         if (!$account->hasPermission($map[$op]) && !$account->hasPermission($type_map[$op]) && !$account->hasPermission('administer support tickets')) {
             $this->access[$cid] = FALSE;
             return FALSE;
         }
         // There should be at least two revisions. If the vid of the given
         // support_ticket and the vid of the default revision differ, then we already
         // have two different revisions so there is no need for a separate database
         // check. Also, if you try to revert to or delete the default revision, that's
         // not good.
         if ($support_ticket->isDefaultRevision() && ($this->supportTicketStorage->countDefaultLanguageRevisions($support_ticket) == 1 || $op == 'update' || $op == 'delete')) {
             $this->access[$cid] = FALSE;
         } elseif ($account->hasPermission('administer support tickets')) {
             $this->access[$cid] = TRUE;
         } else {
             // First check the access to the default revision and finally, if the
             // support_ticket passed in is not the default revision then access to that,
             // too.
             $this->access[$cid] = $this->supportTicketAccess->access($this->supportTicketStorage->load($support_ticket->id()), $op, $account) && ($support_ticket->isDefaultRevision() || $this->supportTicketAccess->access($support_ticket, $op, $account));
         }
     }
     return $this->access[$cid];
 }