Converter.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Cron\Model\Backend\Config\Structure;
  7. class Converter
  8. {
  9. /**
  10. * @var \Magento\Cron\Model\Groups\Config\Data
  11. */
  12. protected $groupsConfig;
  13. /**
  14. * @param \Magento\Cron\Model\Groups\Config\Data $groupsConfig
  15. */
  16. public function __construct(\Magento\Cron\Model\Groups\Config\Data $groupsConfig)
  17. {
  18. $this->groupsConfig = $groupsConfig;
  19. }
  20. /**
  21. * Modify system configuration for cron
  22. *
  23. * @param \Magento\Config\Model\Config\Structure\Converter $subject
  24. * @param array $result
  25. *
  26. * @return array
  27. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  28. * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  29. */
  30. public function afterConvert(\Magento\Config\Model\Config\Structure\Converter $subject, array $result)
  31. {
  32. $groupIterator = 0;
  33. if (!isset($result['config']['system']['sections']['system']['children']['cron']['children']['template'])) {
  34. return $result;
  35. }
  36. foreach ($this->groupsConfig->get() as $group => $fields) {
  37. $template = $result['config']['system']['sections']['system']['children']['cron']['children']['template'];
  38. $template['id'] = $group;
  39. $template['label'] .= $group;
  40. $template['sortOrder'] += $groupIterator++;
  41. $fieldIterator = 0;
  42. foreach ($fields as $fieldName => $value) {
  43. $template['children'][$fieldName]['path'] = 'system/cron/' . $group;
  44. $template['children'][$fieldName]['sortOrder'] += $fieldIterator++;
  45. if (isset($value['tooltip'])) {
  46. $template['children'][$fieldName]['tooltip'] = $value['tooltip'];
  47. }
  48. }
  49. $result['config']['system']['sections']['system']['children']['cron']['children'][$group] = $template;
  50. }
  51. unset($result['config']['system']['sections']['system']['children']['cron']['children']['template']);
  52. return $result;
  53. }
  54. }