View source
<?php
namespace Drupal\panels\Plugin\PanelsPattern;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Url;
use Drupal\ctools\ContextMapperInterface;
use Drupal\panels\CachedValuesGetterTrait;
use Drupal\user\SharedTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DefaultPattern extends PluginBase implements PanelsPatternInterface, ContainerFactoryPluginInterface {
use CachedValuesGetterTrait;
protected $contextMapper;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('ctools.context_mapper'));
}
public function __construct(array $configuration, $plugin_id, $plugin_definition, ContextMapperInterface $context_mapper) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->contextMapper = $context_mapper;
}
public function getMachineName($cached_values) {
if (isset($cached_values['page_variant'])) {
return implode('--', [
$cached_values['id'],
$cached_values['page_variant']
->id(),
]);
}
return $cached_values['id'];
}
public function getDefaultContexts(SharedTempStoreFactory $tempstore, $tempstore_id, $machine_name) {
$cached_values = $this
->getCachedValues($tempstore, $tempstore_id, $machine_name);
if (!empty($cached_values['page_variant'])) {
$page_variant = $cached_values['page_variant'];
return $page_variant
->getContexts();
}
return !empty($cached_values['contexts']) ? $this->contextMapper
->getContextValues($cached_values['contexts']) : [];
}
public function getBlockListUrl($tempstore_id, $machine_name, $region = NULL, $destination = NULL) {
return Url::fromRoute('panels.select_block', [
'tempstore_id' => $tempstore_id,
'machine_name' => $machine_name,
'region' => $region,
'destination' => $destination,
]);
}
public function getBlockAddUrl($tempstore_id, $machine_name, $block_id, $region = NULL, $destination = NULL) {
return Url::fromRoute('panels.add_block', [
'tempstore_id' => $tempstore_id,
'machine_name' => $machine_name,
'block_id' => $block_id,
'region' => $region,
'destination' => $destination,
]);
}
public function getBlockEditUrl($tempstore_id, $machine_name, $block_id, $destination = NULL) {
return Url::fromRoute('panels.edit_block', [
'tempstore_id' => $tempstore_id,
'machine_name' => $machine_name,
'block_id' => $block_id,
'destination' => $destination,
]);
}
public function getBlockDeleteUrl($tempstore_id, $machine_name, $block_id, $destination = NULL) {
return Url::fromRoute('panels.delete_block', [
'tempstore_id' => $tempstore_id,
'machine_name' => $machine_name,
'block_id' => $block_id,
'destination' => $destination,
]);
}
}