function MockBlockManager::createContextDefinition

Same name in other branches
  1. 9 core/modules/system/tests/modules/plugin_test/src/Plugin/MockBlockManager.php \Drupal\plugin_test\Plugin\MockBlockManager::createContextDefinition()
  2. 8.9.x core/modules/system/tests/modules/plugin_test/src/Plugin/MockBlockManager.php \Drupal\plugin_test\Plugin\MockBlockManager::createContextDefinition()
  3. 11.x 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 142

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 assertEquals() checks on arrays that
    // include ContextDefinition objects, and var_export() has problems
    // printing TranslatableMarkup objects.
    $class = ContextDefinition::class;
    if (str_starts_with($data_type, 'entity:')) {
        $class = EntityContextDefinition::class;
    }
    return new $class($data_type, (string) $label, $required);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.