Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DownloadablePanel.php
Go to the documentation of this file.
1 <?php
7 
15 
21 {
25  protected $locator;
26 
30  protected $arrayManager;
31 
35  protected $meta = [];
36 
42  {
43  $this->locator = $locator;
44  $this->arrayManager = $arrayManager;
45  }
46 
50  public function modifyData(array $data)
51  {
52  $model = $this->locator->getProduct();
53 
55  ($model->getTypeId() === Type::TYPE_DOWNLOADABLE) ? '1' : '0';
56 
57  return $data;
58  }
59 
63  public function modifyMeta(array $meta)
64  {
65  $this->meta = $meta;
66 
67  $panelConfig['arguments']['data']['config'] = [
68  'componentType' => Form\Fieldset::NAME,
69  'label' => __('Downloadable Information'),
70  'collapsible' => true,
71  'opened' => $this->locator->getProduct()->getTypeId() === Type::TYPE_DOWNLOADABLE,
72  'sortOrder' => '800',
73  'dataScope' => 'data'
74  ];
75  $this->meta = $this->arrayManager->set('downloadable', $this->meta, $panelConfig);
76 
78  $this->addMessageBox();
79 
80  return $this->meta;
81  }
82 
88  protected function addMessageBox()
89  {
90  $messagePath = Composite::CHILDREN_PATH . '/downloadable_message';
91  $messageConfig['arguments']['data']['config'] = [
92  'componentType' => Container::NAME,
93  'component' => 'Magento_Ui/js/form/components/html',
94  'additionalClasses' => 'admin__fieldset-note',
95  'content' => __('To enable the option set the weight to no'),
96  'sortOrder' => 20,
97  'visible' => false,
98  'imports' => [
99  'visible' => '${$.provider}:' . self::DATA_SCOPE_PRODUCT . '.'
101  ],
102  ];
103 
104  $this->meta = $this->arrayManager->set($messagePath, $this->meta, $messageConfig);
105  }
106 
112  protected function addCheckboxIsDownloadable()
113  {
115  $checkboxConfig['arguments']['data']['config'] = [
116  'dataType' => Form\Element\DataType\Number::NAME,
117  'formElement' => Form\Element\Checkbox::NAME,
118  'componentType' => Form\Field::NAME,
119  'component' => 'Magento_Downloadable/js/components/is-downloadable-handler',
120  'description' => __('Is this downloadable Product?'),
122  'sortOrder' => 10,
123  'imports' => [
124  'disabled' => '${$.provider}:' . self::DATA_SCOPE_PRODUCT . '.'
126  ],
127  'valueMap' => [
128  'false' => '0',
129  'true' => '1',
130  ],
131  'samplesFieldset' => 'ns = ${ $.ns }, index=' . Composite::CONTAINER_SAMPLES,
132  'linksFieldset' => 'ns = ${ $.ns }, index=' . Composite::CONTAINER_LINKS,
133  ];
134 
135  $this->meta = $this->arrayManager->set($checkboxPath, $this->meta, $checkboxConfig);
136  }
137 }
__()
Definition: __.php:13
__construct(LocatorInterface $locator, ArrayManager $arrayManager)