Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AlgorithmSelectionButton.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
16 {
20  private $targetName;
21 
25  private $getSourceSelectionAlgorithmList;
26 
30  private $getDefaultSourceSelectionAlgorithmCode;
31 
37  public function __construct(
38  string $targetName,
39  GetSourceSelectionAlgorithmListInterface $getSourceSelectionAlgorithmList,
40  GetDefaultSourceSelectionAlgorithmCodeInterface $getDefaultSourceSelectionAlgorithmCode
41  ) {
42  $this->targetName = $targetName;
43  $this->getSourceSelectionAlgorithmList = $getSourceSelectionAlgorithmList;
44  $this->getDefaultSourceSelectionAlgorithmCode = $getDefaultSourceSelectionAlgorithmCode;
45  }
46 
52  public function getButtonData()
53  {
54  $defaultSAlgorithmCode = $this->getDefaultSourceSelectionAlgorithmCode->execute();
55  return [
56  'label' => __('Source Selection Algorithm'),
57  'class' => 'save ',
58  'data_attribute' => [
59  'mage-init' => [
60  'buttonAdapter' => [
61  'actions' => [
62  [
63  'targetName' => $this->targetName,
64  'actionName' => 'processAlgorithm',
65  'params' => [
66  false,
67  [
68  'algorithmCode' => $defaultSAlgorithmCode,
69  ],
70  ]
71  ]
72  ]
73  ]
74  ]
75  ],
76  'class_name' => Container::SPLIT_BUTTON,
77  'options' => $this->getAlgorithmsListOptions(),
78  'sort_order' => 10,
79  ];
80  }
81 
87  protected function getAlgorithmsListOptions()
88  {
89  $algorithmsList = $this->getSourceSelectionAlgorithmList->execute();
90  $splitButtonOptions = [];
91  foreach ($algorithmsList as $algorithm) {
92  $splitButtonOptions[] = [
93  'label' => $algorithm->getTitle(),
94  'data_attribute' => [
95  'mage-init' => [
96  'buttonAdapter' => [
97  'actions' => [
98  [
99  'targetName' => $this->targetName,
100  'actionName' => 'processAlgorithm',
101  'params' => [
102  false,
103  [
104  'algorithmCode' => $algorithm->getCode(),
105  ],
106  ],
107  ],
108  ],
109  ],
110  ],
111  ],
112  ];
113  }
114 
115  return $splitButtonOptions;
116  }
117 }
__()
Definition: __.php:13
__construct(string $targetName, GetSourceSelectionAlgorithmListInterface $getSourceSelectionAlgorithmList, GetDefaultSourceSelectionAlgorithmCodeInterface $getDefaultSourceSelectionAlgorithmCode)