|
7 | 7 |
|
8 | 8 | use Magento\Customer\Api\CustomerMetadataInterface;
|
9 | 9 | use Magento\Framework\Api\ArrayObjectSearch;
|
| 10 | +use Magento\Framework\App\ObjectManager; |
| 11 | +use Magento\Framework\Json\EncoderInterface; |
| 12 | +use Magento\Framework\Locale\Bundle\DataBundle; |
| 13 | +use Magento\Framework\Locale\ResolverInterface; |
10 | 14 |
|
11 | 15 | /**
|
12 | 16 | * Customer date of birth attribute block
|
13 | 17 | *
|
14 | 18 | * @SuppressWarnings(PHPMD.DepthOfInheritance)
|
| 19 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
15 | 20 | */
|
16 | 21 | class Dob extends AbstractWidget
|
17 | 22 | {
|
@@ -39,24 +44,42 @@ class Dob extends AbstractWidget
|
39 | 44 | */
|
40 | 45 | protected $filterFactory;
|
41 | 46 |
|
| 47 | + /** |
| 48 | + * JSON Encoder |
| 49 | + * |
| 50 | + * @var EncoderInterface |
| 51 | + */ |
| 52 | + private $encoder; |
| 53 | + |
| 54 | + /** |
| 55 | + * @var ResolverInterface |
| 56 | + */ |
| 57 | + private $localeResolver; |
| 58 | + |
42 | 59 | /**
|
43 | 60 | * @param \Magento\Framework\View\Element\Template\Context $context
|
44 | 61 | * @param \Magento\Customer\Helper\Address $addressHelper
|
45 | 62 | * @param CustomerMetadataInterface $customerMetadata
|
46 | 63 | * @param \Magento\Framework\View\Element\Html\Date $dateElement
|
47 | 64 | * @param \Magento\Framework\Data\Form\FilterFactory $filterFactory
|
48 | 65 | * @param array $data
|
| 66 | + * @param EncoderInterface|null $encoder |
| 67 | + * @param ResolverInterface|null $localeResolver |
49 | 68 | */
|
50 | 69 | public function __construct(
|
51 | 70 | \Magento\Framework\View\Element\Template\Context $context,
|
52 | 71 | \Magento\Customer\Helper\Address $addressHelper,
|
53 | 72 | CustomerMetadataInterface $customerMetadata,
|
54 | 73 | \Magento\Framework\View\Element\Html\Date $dateElement,
|
55 | 74 | \Magento\Framework\Data\Form\FilterFactory $filterFactory,
|
56 |
| - array $data = [] |
| 75 | + array $data = [], |
| 76 | + ?EncoderInterface $encoder = null, |
| 77 | + ?ResolverInterface $localeResolver = null |
57 | 78 | ) {
|
58 | 79 | $this->dateElement = $dateElement;
|
59 | 80 | $this->filterFactory = $filterFactory;
|
| 81 | + $this->encoder = $encoder ?? ObjectManager::getInstance()->get(EncoderInterface::class); |
| 82 | + $this->localeResolver = $localeResolver ?? ObjectManager::getInstance()->get(ResolverInterface::class); |
60 | 83 | parent::__construct($context, $addressHelper, $customerMetadata, $data);
|
61 | 84 | }
|
62 | 85 |
|
@@ -378,6 +401,32 @@ public function getFirstDay()
|
378 | 401 | );
|
379 | 402 | }
|
380 | 403 |
|
| 404 | + /** |
| 405 | + * Get translated calendar config json formatted |
| 406 | + * |
| 407 | + * @return string |
| 408 | + */ |
| 409 | + public function getTranslatedCalendarConfigJson(): string |
| 410 | + { |
| 411 | + $localeData = (new DataBundle())->get($this->localeResolver->getLocale()); |
| 412 | + $monthsData = $localeData['calendar']['gregorian']['monthNames']; |
| 413 | + $daysData = $localeData['calendar']['gregorian']['dayNames']; |
| 414 | + |
| 415 | + return $this->encoder->encode( |
| 416 | + [ |
| 417 | + 'closeText' => __('Done'), |
| 418 | + 'prevText' => __('Prev'), |
| 419 | + 'nextText' => __('Next'), |
| 420 | + 'currentText' => __('Today'), |
| 421 | + 'monthNames' => array_values(iterator_to_array($monthsData['format']['wide'])), |
| 422 | + 'monthNamesShort' => array_values(iterator_to_array($monthsData['format']['abbreviated'])), |
| 423 | + 'dayNames' => array_values(iterator_to_array($daysData['format']['wide'])), |
| 424 | + 'dayNamesShort' => array_values(iterator_to_array($daysData['format']['abbreviated'])), |
| 425 | + 'dayNamesMin' => array_values(iterator_to_array($daysData['format']['short'])), |
| 426 | + ] |
| 427 | + ); |
| 428 | + } |
| 429 | + |
381 | 430 | /**
|
382 | 431 | * Set 2 places for day value in format string
|
383 | 432 | *
|
|
0 commit comments