123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Customer\Ui\Component\MassAction\Group;
- use Magento\Framework\Phrase;
- use Magento\Framework\UrlInterface;
- use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
- /**
- * Class Options
- */
- class Options implements \JsonSerializable
- {
- /**
- * @var array
- */
- protected $options;
- /**
- * @var CollectionFactory
- */
- protected $collectionFactory;
- /**
- * Additional options params
- *
- * @var array
- */
- protected $data;
- /**
- * @var UrlInterface
- */
- protected $urlBuilder;
- /**
- * Base URL for subactions
- *
- * @var string
- */
- protected $urlPath;
- /**
- * Param name for subactions
- *
- * @var string
- */
- protected $paramName;
- /**
- * Additional params for subactions
- *
- * @var array
- */
- protected $additionalData = [];
- /**
- * Constructor
- *
- * @param CollectionFactory $collectionFactory
- * @param UrlInterface $urlBuilder
- * @param array $data
- */
- public function __construct(
- CollectionFactory $collectionFactory,
- UrlInterface $urlBuilder,
- array $data = []
- ) {
- $this->collectionFactory = $collectionFactory;
- $this->data = $data;
- $this->urlBuilder = $urlBuilder;
- }
- /**
- * Get action options
- *
- * @return array
- */
- public function jsonSerialize()
- {
- if ($this->options === null) {
- $options = $this->collectionFactory->create()->setRealGroupsFilter()->toOptionArray();
- $this->prepareData();
- foreach ($options as $optionCode) {
- $this->options[$optionCode['value']] = [
- 'type' => 'customer_group_' . $optionCode['value'],
- 'label' => __($optionCode['label']),
- ];
- if ($this->urlPath && $this->paramName) {
- $this->options[$optionCode['value']]['url'] = $this->urlBuilder->getUrl(
- $this->urlPath,
- [$this->paramName => $optionCode['value']]
- );
- }
- $this->options[$optionCode['value']] = array_merge_recursive(
- $this->options[$optionCode['value']],
- $this->additionalData
- );
- }
- $this->options = array_values($this->options);
- }
- return $this->options;
- }
- /**
- * Prepare addition data for subactions
- *
- * @return void
- */
- protected function prepareData()
- {
- foreach ($this->data as $key => $value) {
- switch ($key) {
- case 'urlPath':
- $this->urlPath = $value;
- break;
- case 'paramName':
- $this->paramName = $value;
- break;
- case 'confirm':
- foreach ($value as $messageName => $message) {
- $this->additionalData[$key][$messageName] = (string) new Phrase($message);
- }
- break;
- default:
- $this->additionalData[$key] = $value;
- break;
- }
- }
- }
- }
|