BlogController.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Drupal\dr8_zth\Controller;
  3. use Drupal\Component\Utility\Xss;
  4. use Drupal\Core\Controller\ControllerBase;
  5. use Drupal\dr8_zth\BlogInterface;
  6. use Drupal\dr8_zth\BlogTypeInterface;
  7. use Drupal\taxonomy\TermInterface;
  8. use Drupal\taxonomy\VocabularyInterface;
  9. /**
  10. * Provides route responses for dr8_zth.module.
  11. */
  12. class BlogController extends ControllerBase {
  13. /**
  14. * Returns a form to add a new term to a vocabulary.
  15. *
  16. * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary
  17. * The vocabulary this term will be added to.
  18. *
  19. * @return array
  20. * The taxonomy term add form.
  21. */
  22. public function addForm(VocabularyInterface $taxonomy_vocabulary) {
  23. $term = $this->entityManager()->getStorage('taxonomy_term')->create(array('vid' => $taxonomy_vocabulary->id()));
  24. return $this->entityFormBuilder()->getForm($term);
  25. }
  26. /**
  27. * Route title callback.
  28. *
  29. * @param \Drupal\dr8_zth\BlogTypeInterface $blog_type
  30. * The blog type instance.
  31. *
  32. * @return string
  33. * The blog type label as a render array.
  34. */
  35. public function typeTitle(BlogTypeInterface $blog_type) {
  36. return ['#markup' => $blog_type->label(), '#allowed_tags' => Xss::getHtmlTagList()];
  37. }
  38. /**
  39. * Route title callback.
  40. *
  41. * @param \Drupal\dr8_zth\BlogInterface $blog
  42. * The blog instance.
  43. *
  44. * @return array
  45. * The blog label as a render array.
  46. */
  47. public function blogTitle(BlogInterface $blog) {
  48. $ret = ['#markup' => $blog->label(), '#allowed_tags' => Xss::getHtmlTagList()];
  49. ksm($ret);
  50. return $ret;
  51. }
  52. }