class Panels in Panels 8.3
Same name and namespace in other branches
- 8.4 src/Controller/Panels.php \Drupal\panels\Controller\Panels
Provides route controllers for Panels routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\panels\Controller\Panels uses AjaxFormTrait, CachedValuesGetterTrait
Expanded class hierarchy of Panels
3 string references to 'Panels'
- page_manager.page_variant.test_page-panels_variant-0.yml in panels_ipe/
tests/ modules/ panels_ipe_page_manager_test_config/ config/ install/ page_manager.page_variant.test_page-panels_variant-0.yml - panels_ipe/tests/modules/panels_ipe_page_manager_test_config/config/install/page_manager.page_variant.test_page-panels_variant-0.yml
- panels.info.yml in ./
panels.info.yml - panels.info.yml
- panels_ipe.info.yml in panels_ipe/
panels_ipe.info.yml - panels_ipe/panels_ipe.info.yml
File
- src/
Controller/ Panels.php, line 22
Namespace
Drupal\panels\ControllerView source
class Panels extends ControllerBase {
use AjaxFormTrait;
use CachedValuesGetterTrait;
/**
* The block manager.
*
* @var \Drupal\Core\Block\BlockManagerInterface
*/
protected $blockManager;
/**
* The condition manager.
*
* @var \Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface
*/
protected $conditionManager;
/**
* The variant manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $variantManager;
/**
* The context handler.
*
* @var \Drupal\Core\Plugin\Context\ContextHandlerInterface
*/
protected $contextHandler;
/**
* Tempstore factory.
*
* @var \Drupal\user\SharedTempStoreFactory
*/
protected $tempstore;
/**
* Constructs a new VariantPluginEditForm.
*
* @param \Drupal\Core\Block\BlockManagerInterface $block_manager
* The block manager.
* @param \Drupal\Component\Plugin\PluginManagerInterface $condition_manager
* The condition manager.
* @param \Drupal\Component\Plugin\PluginManagerInterface $variant_manager
* The variant manager.
* @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $context_handler
* The context handler.
* @param \Drupal\user\SharedTempStoreFactory $tempstore
* The tempstore factory.
*/
public function __construct(BlockManagerInterface $block_manager, PluginManagerInterface $condition_manager, PluginManagerInterface $variant_manager, ContextHandlerInterface $context_handler, SharedTempStoreFactory $tempstore) {
$this->blockManager = $block_manager;
$this->conditionManager = $condition_manager;
$this->variantManager = $variant_manager;
$this->contextHandler = $context_handler;
$this->tempstore = $tempstore;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.block'), $container
->get('plugin.manager.condition'), $container
->get('plugin.manager.display_variant'), $container
->get('context.handler'), $container
->get('user.shared_tempstore'), $container
->get('plugin.manager.panels.pattern'));
}
/**
* Presents a list of blocks to add to the variant.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
* @param string $machine_name
* The identifier of the block display variant.
* @param string $tempstore_id
* The identifier of the temporary store.
*
* @return array
* The block selection page.
*/
public function selectBlock(Request $request, $machine_name, $tempstore_id) {
$cached_values = $this
->getCachedValues($this->tempstore, $tempstore_id, $machine_name);
/** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $variant_plugin */
$variant_plugin = $cached_values['plugin'];
/** @var \Drupal\panels\Plugin\PanelsPattern\PanelsPatternInterface $pattern_plugin */
$pattern_plugin = $variant_plugin
->getPattern();
$contexts = $pattern_plugin
->getDefaultContexts($this->tempstore, $tempstore_id, $machine_name);
$variant_plugin
->setContexts($contexts);
// Add a section containing the available blocks to be added to the variant.
$build = [
'#type' => 'container',
'#attached' => [
'library' => [
'core/drupal.ajax',
],
],
];
$available_plugins = $this->blockManager
->getDefinitionsForContexts($variant_plugin
->getContexts());
// Order by category, and then by admin label.
$available_plugins = $this->blockManager
->getSortedDefinitions($available_plugins);
foreach ($available_plugins as $plugin_id => $plugin_definition) {
// Make a section for each region.
$category = $plugin_definition['category'];
$category_key = 'category-' . $category;
if (!isset($build[$category_key])) {
$build[$category_key] = [
'#type' => 'fieldgroup',
'#title' => $category,
'content' => [
'#theme' => 'links',
],
];
}
// Add a link for each available block within each region.
$build[$category_key]['content']['#links'][$plugin_id] = [
'title' => $plugin_definition['admin_label'],
'url' => $pattern_plugin
->getBlockAddUrl($tempstore_id, $machine_name, $plugin_id, $request->query
->get('region'), $request->query
->get('destination')),
'attributes' => $this
->getAjaxAttributes(),
];
}
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AjaxFormTrait:: |
public static | function | Gets attributes for use with an AJAX modal. | |
AjaxFormTrait:: |
public static | function | Gets attributes for use with an add button AJAX modal. | |
CachedValuesGetterTrait:: |
protected | function | Gets cached values for non-wizard classes that interact with a wizard. | |
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
Panels:: |
protected | property | The block manager. | |
Panels:: |
protected | property | The condition manager. | |
Panels:: |
protected | property | The context handler. | |
Panels:: |
protected | property | Tempstore factory. | |
Panels:: |
protected | property | The variant manager. | |
Panels:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
Panels:: |
public | function | Presents a list of blocks to add to the variant. | |
Panels:: |
public | function | Constructs a new VariantPluginEditForm. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |