PageTemplateSuggestions.php in Context 8
File
src/Plugin/ContextReaction/PageTemplateSuggestions.php
View source
<?php
namespace Drupal\context\Plugin\ContextReaction;
use Drupal\context\ContextReactionPluginBase;
use Drupal\Core\Form\FormStateInterface;
class PageTemplateSuggestions extends ContextReactionPluginBase {
public function summary() {
return $this
->t('Gives you ability to add template suggestions.');
}
public function execute() {
$config = $this
->getConfiguration();
return $config['suggestions'];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$config = $this
->getConfiguration();
$form['suggestions'] = [
'#type' => 'textarea',
'#title' => $this
->t('Page template suggestions'),
'#default_value' => isset($config['suggestions']) ? $config['suggestions'] : '',
'#description' => $this
->t('Enter page template suggestions such as "page__front", one per line, in order of preference (using underscores instead of hyphens). Entered template suggestions will override page.html.twig template.'),
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$config['suggestions'] = str_replace("\r\n", "\n", $form_state
->getValue('suggestions'));
$this
->setConfiguration($config);
}
}