Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PreventDisablingDefaultSourcePlugin.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
16 {
20  private $defaultSourceProvider;
21 
25  private $request;
26 
31  public function __construct(
32  DefaultSourceProviderInterface $defaultSourceProvider,
33  RequestInterface $request
34  ) {
35  $this->defaultSourceProvider = $defaultSourceProvider;
36  $this->request = $request;
37  }
38 
44  public function afterGetMeta(
45  SourceDataProvider $subject,
46  $meta
47  ): array {
48  $isFormComponent = SourceDataProvider::SOURCE_FORM_NAME === $subject->getName();
49  if (!$isFormComponent || !$this->isDefaultSource()) {
50  return $meta;
51  }
52 
53  $meta['general'] = [
54  'children' => [
55  'enabled' => [
56  'arguments' => [
57  'data' => [
58  'config' => [
59  'disabled' => true,
60  ]
61  ]
62  ]
63  ]
64  ]
65  ];
66 
67  return $meta;
68  }
69 
73  private function isDefaultSource(): bool
74  {
75  $defaultSourceCode = $this->defaultSourceProvider->getCode();
76  $currentSourceCode = $this->request->getParam(SourceItemInterface::SOURCE_CODE);
77  return $defaultSourceCode === $currentSourceCode;
78  }
79 }