CollectionTimeLabel.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\Block\Adminhtml\System\Config;
  7. use Magento\Framework\App\ObjectManager;
  8. /**
  9. * Provides label with default Time Zone
  10. */
  11. class CollectionTimeLabel extends \Magento\Config\Block\System\Config\Form\Field
  12. {
  13. /**
  14. * @var \Magento\Framework\Locale\ResolverInterface
  15. */
  16. private $localeResolver;
  17. /**
  18. * @param \Magento\Backend\Block\Template\Context $context
  19. * @param array $data
  20. * @param \Magento\Framework\Locale\ResolverInterface|null $localeResolver
  21. */
  22. public function __construct(
  23. \Magento\Backend\Block\Template\Context $context,
  24. array $data = [],
  25. \Magento\Framework\Locale\ResolverInterface $localeResolver = null
  26. ) {
  27. $this->localeResolver = $localeResolver ?:
  28. ObjectManager::getInstance()->get(\Magento\Framework\Locale\ResolverInterface::class);
  29. parent::__construct($context, $data);
  30. }
  31. /**
  32. * Add current time zone to comment, properly translated according to locale
  33. *
  34. * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  35. * @return string
  36. */
  37. public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
  38. {
  39. $timeZoneCode = $this->_localeDate->getConfigTimezone();
  40. $locale = $this->localeResolver->getLocale();
  41. $getLongTimeZoneName = \IntlTimeZone::createTimeZone($timeZoneCode)
  42. ->getDisplayName(false, \IntlTimeZone::DISPLAY_LONG, $locale);
  43. $element->setData(
  44. 'comment',
  45. sprintf("%s (%s)", $getLongTimeZoneName, $timeZoneCode)
  46. );
  47. return parent::render($element);
  48. }
  49. }