Skip to content

Commit

Permalink
Issue #3059387 by b_sharpe, AaronChristian: Taxonomy Terms cannot be …
Browse files Browse the repository at this point in the history
…rendered when in preview: EntityMalformedException

(cherry picked from commit a35bbafcd36a2fdcb818839034becf01f8187d89)
  • Loading branch information
webchick committed Feb 27, 2020
1 parent 4a19e51 commit aea334d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/rdf/rdf.module
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ function rdf_preprocess_taxonomy_term(&$variables) {
$term = $variables['term'];
$mapping = rdf_get_mapping('taxonomy_term', $term->bundle());
$bundle_mapping = $mapping->getPreparedBundleMapping();
$variables['attributes']['about'] = $term->toUrl()->toString();
$variables['attributes']['about'] = $variables['url'];
$variables['attributes']['typeof'] = empty($bundle_mapping['types']) ? NULL : $bundle_mapping['types'];

// Add RDFa markup for the taxonomy term name as metadata, if present.
Expand Down
2 changes: 1 addition & 1 deletion modules/taxonomy/taxonomy.module
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function template_preprocess_taxonomy_term(&$variables) {
/** @var \Drupal\taxonomy\TermInterface $term */
$term = $variables['term'];

$variables['url'] = $term->toUrl()->toString();
$variables['url'] = !$term->isNew() ? $term->toUrl()->toString() : NULL;

// Make name field available separately. Skip this custom preprocessing if
// the field display is configurable and skipping has been enabled.
Expand Down
23 changes: 23 additions & 0 deletions modules/taxonomy/tests/src/Kernel/TermKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,27 @@ public function testTaxonomyVocabularyTree() {
$this->assertEqual(5, count($ancestors), 'The term has five ancestors including the term itself.');
}

/**
* Tests that a Term is renderable when unsaved (preview).
*/
public function testTermPreview() {
$entity_manager = \Drupal::entityTypeManager();
$vocabulary = $this->createVocabulary();

// Create a unsaved term.
$term = $entity_manager->getStorage('taxonomy_term')->create([
'vid' => $vocabulary->id(),
'name' => 'Inator',
]);

// Confirm we can get the view of unsaved term.
$render_array = $entity_manager->getViewBuilder('taxonomy_term')
->view($term);
$this->assertTrue(!empty($render_array), 'Term view builder is built.');

// Confirm we can render said view.
$rendered = \Drupal::service('renderer')->renderPlain($render_array);
$this->assertTrue(!empty(trim($rendered)), 'Term is able to be rendered.');
}

}

0 comments on commit aea334d

Please sign in to comment.