/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->supportTicketStorage->deleteRevision($this->revision->getRevisionId()); $this->logger('content')->notice('@type: deleted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId())); $support_ticket_type = $this->supportTicketTypeStorage->load($this->revision->bundle())->label(); drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($this->revision->getRevisionCreationTime()), '@type' => $support_ticket_type, '%title' => $this->revision->label()))); $form_state->setRedirect('entity.support_ticket.canonical', array('support_ticket' => $this->revision->id())); if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {support_ticket_field_revision} WHERE stid = :stid', array(':stid' => $this->revision->id()))->fetchField() > 1) { $form_state->setRedirect('entity.support_ticket.version_history', array('support_ticket' => $this->revision->id())); } }
/** * Alter the links of a support ticket. * * @param array &$links * A renderable array representing the support ticket links. * @param \Drupal\support_ticket\SupportTicketInterface $entity * The support ticket being rendered. * @param array &$context * Various aspects of the context in which the support ticket links are going to be * displayed, with the following keys: * - 'view_mode': the view mode in which the support ticket is being viewed * - 'langcode': the language in which the support ticket is being viewed * * @see \Drupal\support_ticket\SupportTicketViewBuilder::renderLinks() * @see \Drupal\support_ticket\SupportTicketViewBuilder::buildLinks() * @see entity_crud */ function hook_support_ticket_links_alter(array &$links, SupportTicketInterface $entity, array &$context) { $links['mymodule'] = array('#theme' => 'links__support_ticket__mymodule', '#attributes' => array('class' => array('links', 'inline')), '#links' => array('support_ticket-report' => array('title' => t('Report'), 'href' => "support_ticket/{$entity->id()}/report", 'query' => array('token' => \Drupal::getContainer()->get('csrf_token')->get("support_ticket/{$entity->id()}/report"))))); }
/** * {@inheritdoc} */ public function countDefaultLanguageRevisions(SupportTicketInterface $support_ticket) { return $this->database->query('SELECT COUNT(*) FROM {support_ticket_field_revision} WHERE stid = :stid AND default_langcode = 1', array(':stid' => $support_ticket->id()))->fetchField(); }
/** * Prepares a revision to be reverted. * * @param \Drupal\support_ticket\SupportTicketInterface $revision * The revision to be reverted. * * @return \Drupal\support_ticket\SupportTicketInterface * The prepared revision ready to be stored. */ protected function prepareRevertedRevision(SupportTicketInterface $revision) { /** @var \Drupal\support_ticket\SupportTicketInterface $default_revision */ $default_revision = $this->supportTicketStorage->load($revision->id()); // If the entity is translated, make sure only translations affected by the // specified revision are reverted. $languages = $default_revision->getTranslationLanguages(); if (count($languages) > 1) { foreach ($languages as $langcode => $language) { if ($revision->hasTranslation($langcode) && !$revision->getTranslation($langcode)->isRevisionTranslationAffected()) { $revision_translation = $revision->getTranslation($langcode); $default_translation = $default_revision->getTranslation($langcode); foreach ($default_revision->getFieldDefinitions() as $field_name => $definition) { if ($definition->isTranslatable()) { $revision_translation->set($field_name, $default_translation->get($field_name)->getValue()); } } } } } $revision->setNewRevision(); $revision->isDefaultRevision(TRUE); return $revision; }