ContextMetadata.php in Context Metadata 8.2
File
src/Plugin/ContextReaction/ContextMetadata.php
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) {
$metatagManager = \Drupal::service('metatag.manager');
$sortedTags = $metatagManager
->sortedTags();
$values = [];
foreach ($sortedTags as $tagId => $tagDefinition) {
if (isset($this
->getConfiguration()[$tagId])) {
$values[$tagId] = $this
->getConfiguration()[$tagId];
}
}
$form = $metatagManager
->form($values, []);
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$metatagManager = \Drupal::service('metatag.manager');
$sortedTags = $metatagManager
->sortedTags();
$conf = [];
foreach ($sortedTags as $tagId => $tagDefinition) {
if ($form_state
->hasValue([
$tagDefinition['group'],
$tagId,
])) {
$conf[$tagId] = $form_state
->getValue([
$tagDefinition['group'],
$tagId,
]);
}
}
$this
->setConfiguration($conf);
}
public function summary() {
return $this
->getConfiguration()['context_metadata'];
}
public function execute(array &$vars = []) {
$config = $this
->getConfiguration();
return $config;
}
}