Example #1
0
 /**
  * Ensures correct entity URLs with the method language-content-entity enabled.
  *
  * Test case with the method language-content-entity enabled and configured
  * with higher and also with lower priority than the method language-url.
  */
 public function testEntityUrlLanguageWithLanguageContentEnabled()
 {
     // Define the method language-content-entity with a higher priority than
     // language-url.
     $config = $this->config('language.types');
     $config->set('configurable', [LanguageInterface::TYPE_INTERFACE, LanguageInterface::TYPE_CONTENT]);
     $config->set('negotiation.language_content.enabled', [LanguageNegotiationContentEntity::METHOD_ID => 0, LanguageNegotiationUrl::METHOD_ID => 1]);
     $config->save();
     // Without being on an content entity route the default entity URL tests
     // should still pass.
     $this->testEntityUrlLanguage();
     // Now switching to an entity route, so that the URL links are generated
     // while being on an entity route.
     $this->setCurrentRequestForRoute('/entity_test/{entity_test}', 'entity.entity_test.canonical');
     // The method language-content-entity should run before language-url and
     // append query parameter for the content language and prevent language-url
     // from overwriting the url.
     $this->assertTrue(strpos($this->entity->urlInfo('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=en') !== FALSE);
     $this->assertTrue(strpos($this->entity->getTranslation('es')->urlInfo('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=es') !== FALSE);
     $this->assertTrue(strpos($this->entity->getTranslation('fr')->urlInfo('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=fr') !== FALSE);
     // Define the method language-url with a higher priority than
     // language-content-entity. This configuration should match the default one,
     // where the language-content-entity is turned off.
     $config->set('negotiation.language_content.enabled', [LanguageNegotiationUrl::METHOD_ID => 0, LanguageNegotiationContentEntity::METHOD_ID => 1]);
     $config->save();
     // The default entity URL tests should pass again with the current
     // configuration.
     $this->testEntityUrlLanguage();
 }
 protected function getRevisionDescription(ContentEntityInterface $revision, $is_current = FALSE)
 {
     /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\user\EntityOwnerInterface $revision */
     if ($revision instanceof EntityOwnerInterface) {
         $username = ['#theme' => 'username', '#account' => $revision->getOwner()];
     } else {
         $username = '';
     }
     if ($revision instanceof ExpandedEntityRevisionInterface) {
         // Use revision link to link to revisions that are not active.
         $date = $this->dateFormatter()->format($revision->getRevisionCreationTime(), 'short');
         if (!$is_current) {
             $link = $this->l($date, $revision->urlInfo('revision'));
         } else {
             $link = $revision->link($date);
         }
     } else {
         $link = $revision->link($revision->label(), 'revision');
     }
     $markup = '';
     if ($revision instanceof EntityRevisionLogInterface) {
         $markup = $revision->getRevisionLog();
     }
     if ($username) {
         $template = '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}';
     } else {
         $template = '{% trans %} {{ date }} {% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}';
     }
     $column = ['data' => ['#type' => 'inline_template', '#template' => $template, '#context' => ['date' => $link, 'username' => $this->renderer()->renderPlain($username), 'message' => ['#markup' => $markup, '#allowed_tags' => Xss::getHtmlTagList()]]]];
     return $column;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->entityManager->getStorage($this->entityRevision->getEntityTypeId())->deleteRevision($this->entityRevision->getRevisionId());
     $this->logger('content')->notice('@type: deleted %title revision %revision.', ['@type' => $this->entityRevision->bundle(), '%title' => $this->entityRevision->label(), '%revision' => $this->entityRevision->getRevisionId()]);
     drupal_set_message(t('@type %title has been deleted', ['@type' => $this->entityRevision->{$this->entityRevision->getEntityType()->getKey('bundle')}->entity->label(), '%title' => $this->entityRevision->label()]));
     $form_state->setRedirectUrl($this->entityRevision->urlInfo('version-history'));
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // The revision timestamp will be updated when the revision is saved. Keep
     // the original one for the confirmation message.
     $this->entityRevision->setNewRevision();
     $this->entityRevision->isDefaultRevision(TRUE);
     if ($this->entityRevision instanceof EntityRevisionLogInterface) {
         if ($this->entityRevision instanceof TimestampedRevisionInterface) {
             $original_revision_timestamp = $this->entityRevision->getRevisionCreationTime();
             $this->entityRevision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
         } else {
             $this->entityRevision->revision_log = t('Copy of the revision');
         }
     }
     $this->entityRevision->save();
     $this->logger('content')->notice('@type: reverted %title revision %revision.', ['@type' => $this->entityRevision->bundle(), '%title' => $this->entityRevision->label(), '%revision' => $this->entityRevision->getRevisionId()]);
     drupal_set_message(t('@type %title has been reverted to the revision', ['@type' => $this->entityRevision->{$this->entityRevision->getEntityType()->getKey('bundle')}->entity->label(), '%title' => $this->entityRevision->label()]));
     $form_state->setRedirectUrl($this->entityRevision->urlInfo('version-history'));
 }