Skip to content

Commit fcdc2d7

Browse files
author
Derek Reese
committed
Adds work from SiliconValet/patternkit8musing
1 parent 002d71b commit fcdc2d7

File tree

3 files changed

+94
-4
lines changed

3 files changed

+94
-4
lines changed

patternkit.info.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
name: Patternkit
2-
description: Adds Patternkit patterns to panels as content types.
2+
description: Adds Patternkit patterns as blocks.
3+
type: module
34
package: Presentation Framework
45
core: 8.x
5-
dependencies:
6-
- drupal:ctools
7-
- drupal:panels

src/Plugin/Block/PatternkitBlock.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Drupal\patternkit\Plugin\Block;
4+
5+
use Drupal\Core\Block\BlockBase;
6+
7+
/**
8+
* Display all instances for 'PatternkitBlock' block plugin.
9+
*
10+
* @Block(
11+
* id = "patternkit_block",
12+
* admin_label = @Translation("Patternkit block"),
13+
* category="Patternkit",
14+
* deriver = "Drupal\patternkit\Plugin\Derivative\PatternkitBlock"
15+
* )
16+
*/
17+
class PatternkitBlock extends BlockBase {
18+
/**
19+
* Build the content for PatternKit block.
20+
*/
21+
public function build() {
22+
$block_id = $this->getDerivativeId();
23+
return array(
24+
'#markup' => $block_id,
25+
);
26+
}
27+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Drupal\patternkit\Plugin\Derivative;
4+
5+
use Drupal\Component\Plugin\Derivative\DeriverBase;
6+
use Drupal\Core\Plugin\Context\ContextDefinition;
7+
8+
class PatternkitBlock extends DeriverBase {
9+
10+
/**
11+
* {@inheritDoc}
12+
*/
13+
public function getDerivativeDefinitions($base_plugin_definition) {
14+
15+
// @TODO: Replace with LoadPatterns service.
16+
$patterns = [
17+
'pattern1' => [
18+
'admin_label' => 'Some pattern (a)',
19+
'context' => [
20+
'node' => new ContextDefinition("entity:node"),
21+
]
22+
],
23+
'pattern2' => [
24+
'admin_label' => 'Some pattern (b)',
25+
'context' => [
26+
'user' => new ContextDefinition("entity:user"),
27+
]
28+
],
29+
'pattern3' => [
30+
'admin_label' => 'Some pattern (c)',
31+
],
32+
];
33+
34+
// @TODO: Extend the base plugin definition.
35+
36+
foreach ($patterns as $idx => $pattern) {
37+
$patternLibrary = 'PFE';
38+
$patternGroup = 'atoms';
39+
$patternName = $pattern['admin_label'];
40+
41+
$this->derivatives[$idx] = $base_plugin_definition;
42+
$this->derivatives[$idx] += $pattern;
43+
$this->derivatives[$idx] += [
44+
'category' => t(
45+
'Patternkit:@lib/@group',
46+
[
47+
'@lib' => $patternLibrary,
48+
'@group' => $patternGroup,
49+
'@pattern' => $patternName,
50+
]
51+
),
52+
'admin_label' => t(
53+
'[Patternkit] @pattern',
54+
[
55+
'@pattern' => $pattern['admin_label'],
56+
]
57+
),
58+
];
59+
60+
61+
}
62+
63+
return $this->derivatives;
64+
}
65+
}

0 commit comments

Comments
 (0)