PanelizerWizardContextConfigure.php in Panelizer 8.4
File
src/Form/PanelizerWizardContextConfigure.php
View source
<?php
namespace Drupal\panelizer\Form;
use Drupal\Core\Plugin\Context\ContextInterface;
use Drupal\ctools\Form\ContextConfigure;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PanelizerWizardContextConfigure extends ContextConfigure {
protected $contextMapper;
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->contextMapper = $container
->get('ctools.context_mapper');
return $instance;
}
protected function getParentRouteInfo($cached_values) {
return [
'panelizer.wizard.add.step',
[
'machine_name' => $cached_values['id'],
'step' => 'contexts',
],
];
}
protected function getContexts($cached_values) {
$static_contexts = isset($cached_values['contexts']) ? $cached_values['contexts'] : [];
$static_contexts = $this->contextMapper
->getContextValues($static_contexts);
return $static_contexts;
}
protected function addContext($cached_values, $context_id, ContextInterface $context) {
$cached_values['contexts'][$context_id] = [
'label' => $context
->getContextDefinition()
->getLabel(),
'type' => $context
->getContextDefinition()
->getDataType(),
'description' => $context
->getContextDefinition()
->getDescription(),
'value' => strpos($context
->getContextDefinition()
->getDataType(), 'entity:') === 0 ? $context
->getContextValue()
->uuid() : $context
->getContextValue(),
];
return $cached_values;
}
public function contextExists($value, $element, $form_state) {
return FALSE;
}
protected function disableMachineName($cached_values, $machine_name) {
return !empty($cached_values['contexts'][$machine_name]);
}
}