You are here

protected function MockBlockManager::createContextDefinition in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/plugin_test/src/Plugin/MockBlockManager.php \Drupal\plugin_test\Plugin\MockBlockManager::createContextDefinition()

Creates a new context definition with a label that is cast to string.

Parameters

string $data_type: The required data type.

mixed|string|null $label: The label of this context definition for the UI.

bool $required: Whether the context definition is required.

Return value

\Drupal\Core\Plugin\Context\ContextDefinition

1 call to MockBlockManager::createContextDefinition()
MockBlockManager::__construct in core/modules/system/tests/modules/plugin_test/src/Plugin/MockBlockManager.php

File

core/modules/system/tests/modules/plugin_test/src/Plugin/MockBlockManager.php, line 139

Class

MockBlockManager
Defines a plugin manager used by Plugin API derivative unit tests.

Namespace

Drupal\plugin_test\Plugin

Code

protected function createContextDefinition($data_type, $label, $required = TRUE) {

  // We cast the label to string for testing purposes only, as it may be
  // a TranslatableMarkup and we will do assertEqual() checks on arrays that
  // include ContextDefinition objects, and var_export() has problems
  // printing TranslatableMarkup objects.
  $class = ContextDefinition::class;
  if (strpos($data_type, 'entity:') === 0) {
    $class = EntityContextDefinition::class;
  }
  return new $class($data_type, (string) $label, $required);
}