View source
<?php
namespace Drupal\context_metadata\Plugin\ContextReaction;
use Drupal\context\ContextReactionPluginBase;
use Drupal\Core\Form\FormStateInterface;
class ContextMetadata extends ContextReactionPluginBase {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['metadata_title'] = array(
'#title' => $this
->t('Meta Title'),
'#description' => $this
->t('Title goes here'),
'#type' => 'textfield',
'#maxlength' => 256,
'#default_value' => $this
->getConfiguration()['metadata_title'],
);
$form['metadata_description'] = array(
'#title' => $this
->t('Meta Description'),
'#description' => $this
->t('Meta Description'),
'#type' => 'textfield',
'#maxlength' => 400,
'#default_value' => $this
->getConfiguration()['metadata_description'],
);
$form['metadata_keywords'] = array(
'#title' => $this
->t('Meta Keywords'),
'#description' => $this
->t('Meta Keywords'),
'#type' => 'textfield',
'#maxlength' => 400,
'#default_value' => $this
->getConfiguration()['metadata_keywords'],
);
$form['metadata_canonical_url'] = array(
'#title' => $this
->t('Canonical URL'),
'#description' => $this
->t('Canonical URL'),
'#type' => 'textfield',
'#maxlength' => 400,
'#default_value' => $this
->getConfiguration()['metadata_canonical_url'],
);
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this
->setConfiguration([
'metadata_title' => $form_state
->getValue('metadata_title'),
'metadata_description' => $form_state
->getValue('metadata_description'),
'metadata_keywords' => $form_state
->getValue('metadata_keywords'),
'metadata_canonical_url' => $form_state
->getValue('metadata_canonical_url'),
]);
}
public function summary() {
return $this
->getConfiguration()['context_metadata'];
}
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'metadata_title' => '',
'metadata_description' => '',
'metadata_keywords' => '',
'metadata_canonical_url' => '',
];
}
public function execute(array &$vars = []) {
$config = $this
->getConfiguration();
return $config;
}
}