You are here

protected function CachedValuesGetterTrait::getCachedValues in Panels 8.4

Same name and namespace in other branches
  1. 8.3 src/CachedValuesGetterTrait.php \Drupal\panels\CachedValuesGetterTrait::getCachedValues()

Gets cached values for non-wizard classes that interact with a wizard.

This method is specifically geared toward the needs of a panels use case both within and outside of PageManager. To that end, some of the logic in here is explicitly checking for known PageManager standards and behaving as necessary to compensate for PageManager's needs. Other Panels implementations are generally simpler and do not need the same degree of customization. This trait accounts for both use cases.

Parameters

\Drupal\Core\TempStore\SharedTempStoreFactory $tempstore: The tempstore object in use for the desired cached values.

string $tempstore_id: The tempstore identifier.

string $machine_name: The tempstore key.

Return value

mixed

6 calls to CachedValuesGetterTrait::getCachedValues()
DefaultPattern::getDefaultContexts in src/Plugin/PanelsPattern/DefaultPattern.php
Gets the array of default contexts for this panels pattern.
Panels::selectBlock in src/Controller/Panels.php
Presents a list of blocks to add to the variant.
PanelsBlockConfigureFormBase::buildForm in src/Form/PanelsBlockConfigureFormBase.php
Form constructor.
PanelsBlockConfigureFormBase::submitForm in src/Form/PanelsBlockConfigureFormBase.php
Form submission handler.
PanelsDeleteBlockForm::buildForm in src/Form/PanelsDeleteBlockForm.php
Form constructor.

... See full list

File

src/CachedValuesGetterTrait.php, line 31

Class

CachedValuesGetterTrait
Provides a method for panels wizards cached values for non-wizard forms.

Namespace

Drupal\panels

Code

protected function getCachedValues(SharedTempStoreFactory $tempstore, $tempstore_id, $machine_name) {
  $machine_name = explode('--', $machine_name);
  $cached_values = $tempstore
    ->get($tempstore_id)
    ->get($machine_name[0]);

  // PageManager specific handling. If $machine_name[1] is set, it's the
  // page variant ID.
  if (isset($machine_name[1]) && !isset($cached_values['page_variant'])) {

    /** @var \Drupal\page_manager\PageInterface $page */
    $page = $cached_values['page'];
    $cached_values['page_variant'] = $page
      ->getVariant($machine_name[1]);
  }
  if (!isset($cached_values['plugin']) && !empty($cached_values['page_variant'])) {
    $cached_values['plugin'] = $cached_values['page_variant']
      ->getVariantPlugin();
  }
  return $cached_values;
}