|
24 | 24 | * @Block(
|
25 | 25 | * id = "patternkit_block",
|
26 | 26 | * admin_label = @Translation("Patternkit block"),
|
27 |
| - * category="Patternkit", |
| 27 | + * category = @Translation("Patternkit Reusable"), |
28 | 28 | * deriver = "Drupal\patternkit\Plugin\Derivative\PatternkitBlock"
|
29 | 29 | * )
|
30 | 30 | */
|
@@ -159,9 +159,12 @@ public function blockForm($form, FormStateInterface $form_state): array {
|
159 | 159 | return ['#markup' => $this->t('Unable to edit a Patternkit block when the pattern fails to load.')];
|
160 | 160 | }
|
161 | 161 | $form_state->set('pattern', $pattern);
|
162 |
| - // Remove the title override fields. |
163 |
| - unset($form['label'], |
164 |
| - $form['label_display']); |
| 162 | + |
| 163 | + $form['reusable'] = [ |
| 164 | + '#type' => 'checkbox', |
| 165 | + '#title' => $this->t('Reusable'), |
| 166 | + '#default_value' => $configuration['reusable'] ?? FALSE, |
| 167 | + ]; |
165 | 168 |
|
166 | 169 | // @TODO: Re-enable the other formats like JSON and webcomponent.
|
167 | 170 | $form['presentation_style'] = [
|
@@ -231,6 +234,7 @@ public function blockSubmit($form, FormStateInterface $form_state) {
|
231 | 234 | $values = [
|
232 | 235 | 'data' => $form_state->getValue('instance_config'),
|
233 | 236 | 'info' => $form_state->getValue('label'),
|
| 237 | + 'reusable' => $form_state->getValue('reusable'), |
234 | 238 | 'published' => TRUE,
|
235 | 239 | ];
|
236 | 240 | /** @var \Drupal\patternkit\Entity\PatternkitBlock $patternkit_block */
|
@@ -414,6 +418,21 @@ public function build() {
|
414 | 418 | return $content;
|
415 | 419 | }
|
416 | 420 |
|
| 421 | + /** |
| 422 | + * {@inheritDoc} |
| 423 | + */ |
| 424 | + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { |
| 425 | + $form = parent::buildConfigurationForm($form, $form_state); |
| 426 | + // Remove the title override fields. |
| 427 | + unset($form['label_display']); |
| 428 | + $form['label']['#states'] = [ |
| 429 | + 'visible' => [ |
| 430 | + ':input[name="settings[reusable]"]' => ['checked' => TRUE], |
| 431 | + ], |
| 432 | + ]; |
| 433 | + return $form; |
| 434 | + } |
| 435 | + |
417 | 436 | /**
|
418 | 437 | * Returns a new PatternkitBlock instance.
|
419 | 438 | *
|
|
0 commit comments