protected function CustomFormattersTestBase::createCustomFormatter in Custom Formatters 8.3
Create a Custom Formatter.
Parameters
array $values: The values to set for the Custom Formatter.
Return value
\Drupal\custom_formatters\FormatterInterface The Custom Formatter object.
4 calls to CustomFormattersTestBase::createCustomFormatter()
- CustomFormattersGeneralTest::testCustomFormatterTypeHtmlToken in src/
Tests/ CustomFormattersGeneralTest.php  - Test the HTML + Token engine.
 - CustomFormattersGeneralTest::testCustomFormatterTypePhp in src/
Tests/ CustomFormattersGeneralTest.php  - Test the PHP Engine.
 - CustomFormattersGeneralTest::testCustomFormatterTypeTwig in src/
Tests/ CustomFormattersGeneralTest.php  - Test the Twig engine.
 - CustomFormattersGeneralTest::testFormatterTypeFormatterPreset in src/
Tests/ CustomFormattersGeneralTest.php  - Test the Formatter preset Engine.
 
File
- src/
Tests/ CustomFormattersTestBase.php, line 117  
Class
- CustomFormattersTestBase
 - Class CustomFormattersTestBase.
 
Namespace
Drupal\custom_formatters\TestsCode
protected function createCustomFormatter($values = []) {
  // Prepare the default values.
  $name = $this
    ->randomMachineName();
  $defaults = [
    'label' => $name,
    'id' => mb_strtolower($name),
    'field_types' => [
      'text_with_summary',
    ],
  ];
  $values += $defaults;
  // Create the Custom Formatter.
  $formatter = \Drupal::entityTypeManager()
    ->getStorage('formatter')
    ->create($values);
  $formatter
    ->save();
  // Clear cached formatters.
  \Drupal::service('plugin.manager.field.formatter')
    ->clearCachedDefinitions();
  return $formatter;
}