MaterioCommerceTermsViewer.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Drupal\materio_commerce\Controller;
  3. use Drupal\Core\Controller\ControllerBase;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Drupal\Core\Language\LanguageManagerInterface;
  6. use Drupal\Core\Url;
  7. use Symfony\Component\HttpFoundation\Request;
  8. // use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Drupal\config_pages\Entity\ConfigPages;
  10. use Drupal\config_pages\Entity\ConfigPagesType;
  11. /**
  12. * Class AjaxHomeController.
  13. */
  14. class MaterioCommerceTermsViewer extends ControllerBase {
  15. /*
  16. * @var \Drupal\Core\Entity\EntityTypeManagerInterface
  17. */
  18. protected $languageManager;
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function create(ContainerInterface $container) {
  23. return new static(
  24. $container->get('language_manager')
  25. );
  26. }
  27. /**
  28. * Constructs a new MaterioDecoupledLanguageLinks object.
  29. *
  30. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
  31. * The language manager.
  32. */
  33. public function __construct(LanguageManagerInterface $language_manager) {
  34. $this->languageManager = $language_manager;
  35. }
  36. /**
  37. * getTerms
  38. *
  39. * @return string
  40. * Return config_page terms_of_services display.
  41. */
  42. public function getTos(Request $request) {
  43. $config_page = $this->getConfigPage();
  44. // Correct metatags attachment.
  45. if (function_exists('metatag_get_tags_from_route')) {
  46. $metatag_attachments = &drupal_static('metatag_attachments');
  47. $metatag_attachments = metatag_get_tags_from_route($config_page);
  48. }
  49. return parent::entityTypeManager()->getViewBuilder('config_pages')->view($config_page, 'full');
  50. }
  51. public function getTitle(Request $request) {
  52. $config_page = $this->getConfigPage();
  53. return $config_page->get('field_title')->getString();
  54. }
  55. private function getConfigPage(){
  56. return ConfigPages::load("terms_of_services");
  57. }
  58. }