Skip to content

Commit 5f1c054

Browse files
author
Willem Wigman
committed
#4 remove obsolete ->id() checks
1 parent 74f7956 commit 5f1c054

File tree

2 files changed

+51
-55
lines changed

2 files changed

+51
-55
lines changed

src/Plugin/CategoryLayoutPlugin.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ class CategoryLayoutPlugin
4444
public function __construct(
4545
FlyweightFactory $themeFactory,
4646
DesignInterface $design,
47-
LayoutProcessorFactory $layoutProcessorFactory
48-
)
47+
LayoutProcessorFactory $layoutProcessorFactory)
4948
{
5049
$this->themeFactory = $themeFactory;
5150
$this->design = $design;
@@ -66,7 +65,7 @@ private function getLayoutProcessor(): LayoutProcessor
6665
[
6766
'theme' => $this->themeFactory->create(
6867
$this->design->getConfigurationDesignTheme(Area::AREA_FRONTEND)
69-
)
68+
),
7069
]
7170
);
7271
$this->themeFactory = null;
@@ -88,32 +87,30 @@ private function getLayoutProcessor(): LayoutProcessor
8887
public function afterFetchAvailableFiles(
8988
LayoutUpdateManager $subject,
9089
array $result,
91-
CategoryInterface $category
92-
): array
90+
CategoryInterface $category): array
9391
{
94-
if (!$category->getId()) {
95-
return $result;
96-
}
97-
9892
$handles = $this->getLayoutProcessor()->getAvailableHandles();
9993

100-
return array_merge($result, array_filter(
101-
array_map(
102-
function(string $handle) use ($category) : ?string {
103-
preg_match(
104-
'/^catalog\_category\_view\_selectable\_0\_([a-z0-9]+)/i',
105-
$handle,
106-
$selectable
107-
);
108-
if (!empty($selectable[1])) {
109-
return $selectable[1];
110-
}
111-
112-
return null;
113-
},
114-
$handles
94+
return array_merge(
95+
$result,
96+
array_filter(
97+
array_map(
98+
function (string $handle): ?string {
99+
preg_match(
100+
'/^catalog\_category\_view\_selectable\_0\_([a-z0-9]+)/i',
101+
$handle,
102+
$selectable
103+
);
104+
if (!empty($selectable[1])) {
105+
return $selectable[1];
106+
}
107+
108+
return null;
109+
},
110+
$handles
111+
)
115112
)
116-
));
113+
);
117114
}
118115

119116
/**
@@ -132,8 +129,7 @@ public function afterExtractCustomSettings(
132129
LayoutUpdateManager $subject,
133130
$result,
134131
CategoryInterface $category,
135-
DataObject $intoSettings
136-
): void
132+
DataObject $intoSettings): void
137133
{
138134
if ($category->getId() && $value = $this->extractAttributeValue($category)) {
139135
$handles = $intoSettings->getPageLayoutHandles() ?? [];

src/Plugin/ProductLayoutPlugin.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
use Magento\Framework\View\Model\Layout\Merge as LayoutProcessor;
1515
use Magento\Framework\View\Model\Layout\MergeFactory as LayoutProcessorFactory;
1616

17-
class ProductLayoutPlugin {
17+
class ProductLayoutPlugin
18+
{
1819

1920
/**
2021
* @var FlyweightFactory
@@ -44,8 +45,8 @@ class ProductLayoutPlugin {
4445
public function __construct(
4546
FlyweightFactory $themeFactory,
4647
DesignInterface $design,
47-
LayoutProcessorFactory $layoutProcessorFactory
48-
) {
48+
LayoutProcessorFactory $layoutProcessorFactory)
49+
{
4950
$this->themeFactory = $themeFactory;
5051
$this->design = $design;
5152
$this->layoutProcessorFactory = $layoutProcessorFactory;
@@ -65,7 +66,7 @@ private function getLayoutProcessor(): LayoutProcessor
6566
[
6667
'theme' => $this->themeFactory->create(
6768
$this->design->getConfigurationDesignTheme(Area::AREA_FRONTEND)
68-
)
69+
),
6970
]
7071
);
7172
$this->themeFactory = null;
@@ -87,31 +88,30 @@ private function getLayoutProcessor(): LayoutProcessor
8788
public function afterFetchAvailableFiles(
8889
LayoutUpdateManager $subject,
8990
array $result,
90-
ProductInterface $product
91-
): array {
92-
if (!$product->getSku()) {
93-
return [];
94-
}
95-
91+
ProductInterface $product): array
92+
{
9693
$handles = $this->getLayoutProcessor()->getAvailableHandles();
9794

98-
return array_merge($result, array_filter(
99-
array_map(
100-
function(string $handle) : ?string {
101-
preg_match(
102-
'/^catalog\_product\_view\_selectable\_0\_([a-z0-9]+)/i',
103-
$handle,
104-
$selectable
105-
);
106-
if (!empty($selectable[1])) {
107-
return $selectable[1];
108-
}
109-
110-
return null;
111-
},
112-
$handles
95+
return array_merge(
96+
$result,
97+
array_filter(
98+
array_map(
99+
function (string $handle): ?string {
100+
preg_match(
101+
'/^catalog\_product\_view\_selectable\_0\_([a-z0-9]+)/i',
102+
$handle,
103+
$selectable
104+
);
105+
if (!empty($selectable[1])) {
106+
return $selectable[1];
107+
}
108+
109+
return null;
110+
},
111+
$handles
112+
)
113113
)
114-
));
114+
);
115115
}
116116

117117
/**
@@ -130,8 +130,8 @@ public function afterExtractCustomSettings(
130130
LayoutUpdateManager $subject,
131131
$result,
132132
ProductInterface $product,
133-
DataObject $intoSettings
134-
): void {
133+
DataObject $intoSettings): void
134+
{
135135
if ($product->getSku() && $value = $this->extractAttributeValue($product)) {
136136
$handles = $intoSettings->getPageLayoutHandles() ?? [];
137137
$handles = array_merge_recursive(

0 commit comments

Comments
 (0)