You are here

public function FormWidgetExampleForm::getExampleContextDefinition in Typed Data API enhancements 8

Gets some example context definition.

Parameters

string $widget_id: The widget id.

Return value

\Drupal\Core\Plugin\Context\ContextDefinitionInterface The definition.

1 call to FormWidgetExampleForm::getExampleContextDefinition()
FormWidgetExampleForm::buildForm in tests/modules/typed_data_widget_test/src/FormWidgetExampleForm.php
Form constructor.

File

tests/modules/typed_data_widget_test/src/FormWidgetExampleForm.php, line 64

Class

FormWidgetExampleForm
Class FormWidgetExampleForm.

Namespace

Drupal\typed_data_widget_test

Code

public function getExampleContextDefinition($widget_id) {
  switch ($widget_id) {
    default:
    case 'text_input':
      return ContextDefinition::create('string')
        ->setLabel('Example string')
        ->setDescription('Some example string with max. 8 characters.')
        ->setDefaultValue('default')
        ->addConstraint('Length', [
        'max' => 8,
      ]);
    case 'textarea':
      return ContextDefinition::create('text')
        ->setLabel('Example text area')
        ->setDefaultValue("default line one\nline two")
        ->setDescription('This is the long textarea example description.');
    case 'select':
      return ContextDefinition::create('filter_format')
        ->setLabel('Filter format')
        ->setDescription('Some example selection.');
    case 'datetime':
      return ContextDefinition::create('datetime_iso8601')
        ->setLabel('Example datetime')
        ->setDescription('Some example datetime.');
    case 'datetime_range':
      return ContextDefinition::create('any')
        ->setLabel('Example datetime range')
        ->setDescription('Some example datetime range.');
    case 'broken':
      return ContextDefinition::create('string')
        ->setLabel('Example string');
  }
}