You are here

class DefaultPattern in Panels 8.3

Same name and namespace in other branches
  1. 8.4 src/Plugin/PanelsPattern/DefaultPattern.php \Drupal\panels\Plugin\PanelsPattern\DefaultPattern

Plugin annotation

@PanelsPattern("default");

Hierarchy

Expanded class hierarchy of DefaultPattern

File

src/Plugin/PanelsPattern/DefaultPattern.php, line 20

Namespace

Drupal\panels\Plugin\PanelsPattern
View source
class DefaultPattern extends PluginBase implements PanelsPatternInterface, ContainerFactoryPluginInterface {
  use CachedValuesGetterTrait;

  /**
   * The context mapper.
   *
   * @var \Drupal\ctools\ContextMapperInterface
   */
  protected $contextMapper;

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * DefaultPattern constructor.
   *
   * @param array $configuration
   *   The plugin's configuration.
   * @param string $plugin_id
   *   The plugin id.
   * @param mixed $plugin_definition
   *   The plugin definition.
   * @param \Drupal\ctools\ContextMapperInterface $context_mapper
   *   The 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;
  }

  /**
   * {@inheritdoc}
   */
  public function getMachineName($cached_values) {

    // PageManager needs special handling, so lets see if we're dealing with a PM page.
    if (isset($cached_values['page_variant'])) {
      return implode('--', [
        $cached_values['id'],
        $cached_values['page_variant']
          ->id(),
      ]);
    }
    return $cached_values['id'];
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultContexts(SharedTempStoreFactory $tempstore, $tempstore_id, $machine_name) {
    $cached_values = $this
      ->getCachedValues($tempstore, $tempstore_id, $machine_name);

    // PageManager specific context loading.
    if (!empty($cached_values['page_variant'])) {

      /** @var \Drupal\page_manager\PageVariantInterface $page_variant */
      $page_variant = $cached_values['page_variant'];
      return $page_variant
        ->getContexts();
    }

    // General handling for contexts.
    return !empty($cached_values['contexts']) ? $this->contextMapper
      ->getContextValues($cached_values['contexts']) : [];
  }

  /**
   * {@inheritdoc}
   */
  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,
    ]);
  }

  /**
   * {@inheritdoc}
   */
  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,
    ]);
  }

  /**
   * {@inheritdoc}
   */
  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,
    ]);
  }

  /**
   * {@inheritdoc}
   */
  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,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CachedValuesGetterTrait::getCachedValues protected function Gets cached values for non-wizard classes that interact with a wizard.
DefaultPattern::$contextMapper protected property The context mapper.
DefaultPattern::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
DefaultPattern::getBlockAddUrl public function Gets the block add url. Overrides PanelsPatternInterface::getBlockAddUrl
DefaultPattern::getBlockDeleteUrl public function Gets the block delete url. Overrides PanelsPatternInterface::getBlockDeleteUrl
DefaultPattern::getBlockEditUrl public function Gets the block edit url. Overrides PanelsPatternInterface::getBlockEditUrl
DefaultPattern::getBlockListUrl public function Gets the block list url. Overrides PanelsPatternInterface::getBlockListUrl
DefaultPattern::getDefaultContexts public function Gets the array of default contexts for this panels pattern. Overrides PanelsPatternInterface::getDefaultContexts
DefaultPattern::getMachineName public function Gets the tempstore key identifier. Overrides PanelsPatternInterface::getMachineName
DefaultPattern::__construct public function DefaultPattern constructor. Overrides PluginBase::__construct
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.