panels_everywhere.module in Panels Everywhere 8.4
Same filename and directory in other branches
File
panels_everywhere.moduleView source
<?php
use Drupal\page_manager\PageVariantInterface;
/**
* Implements hook_ENTITY_TYPE_create().
*
* We need to set the storage information on Panels displays being storaged
* in Page Manager as early as possible, to signal to Panels that features
* requiring Panels storage (like the IPE) are supported.
*
* @see panels_page_variant_presave()
*/
function panels_everywhere_page_variant_create(PageVariantInterface $page_variant) {
if ($page_variant
->getVariantPluginId() == 'panels_everywhere_variant') {
/** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display */
$panels_display = $page_variant
->getVariantPlugin();
// At this point, it very likely that $page_variant->id() is NULL. But
// setting the storage type to 'page_manager' is enough to trigger Panels
// to offer the IPE as an option.
$panels_display
->setStorage('page_manager', $page_variant
->id());
}
}
/**
* Implements hook_ENTITY_TYPE_presave().
*
* Now that we have the id for the page variant, we need to set the storage
* information again.
*
* @see panels_page_variant_create()
*/
function panels_everywhere_page_variant_presave(PageVariantInterface $page_variant) {
if ($page_variant
->getVariantPluginId() == 'panels_everywhere_variant') {
/** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display */
$panels_display = $page_variant
->getVariantPlugin();
// Set the storage info now that we have the id.
$panels_display
->setStorage('page_manager', $page_variant
->id());
// It's ConfigEntityBase::preSave() that copies configuration from plugin
// collections to the config entity, and unfortunately, that runs just
// before invoking hook_entity_presave(). So, we have to copy the
// configuration from $panels_display to $page_variant again manually for
// it to be saved.
$page_variant
->set('variant_settings', $panels_display
->getConfiguration());
}
}
// --------------------------------------------------------------------------
/* Like array_splice(), but preserves the key(s) of the replacement array. */
function array_splice_assoc(&$input, $offset, $length = 0, $replacement = array()) {
$tail = array_splice($input, $offset);
$extracted = array_splice($tail, 0, $length);
$input += $replacement + $tail;
return $extracted;
}
Functions
Name | Description |
---|---|
array_splice_assoc | |
panels_everywhere_page_variant_create | Implements hook_ENTITY_TYPE_create(). |
panels_everywhere_page_variant_presave | Implements hook_ENTITY_TYPE_presave(). |