Commit a35bbafc authored by webchick's avatar webchick
Browse files

Issue #3059387 by b_sharpe, AaronChristian: Taxonomy Terms cannot be rendered...

Issue #3059387 by b_sharpe, AaronChristian: Taxonomy Terms cannot be rendered when in preview: EntityMalformedException
parent d185342b
......@@ -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.
......
......@@ -153,7 +153,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.
......
......@@ -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.');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment