Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
PluginItem
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 4
20
0.00% covered (danger)
0.00%
0 / 1
 defaultFieldSettings
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 propertyDefinitions
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 schema
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getInstance
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\display_builder\Plugin\Field\FieldType;
6
7use Drupal\Core\Field\Attribute\FieldType;
8use Drupal\Core\Field\FieldItemBase;
9use Drupal\Core\Field\FieldItemList;
10use Drupal\Core\Field\FieldStorageDefinitionInterface;
11use Drupal\Core\StringTranslation\TranslatableMarkup;
12use Drupal\Core\TypedData\DataDefinition;
13use Drupal\Core\TypedData\MapDataDefinition;
14
15/**
16 * Store a plugin ID and its configuration to easily create instances.
17 */
18#[FieldType(
19  id: 'plugin',
20  label: new TranslatableMarkup('Plugin'),
21  list_class: FieldItemList::class,
22  no_ui: TRUE,
23)]
24class PluginItem extends FieldItemBase {
25
26  /**
27   * {@inheritdoc}
28   */
29  public static function defaultFieldSettings() {
30    return [
31      'plugin_manager_id' => '',
32    ] + parent::defaultFieldSettings();
33  }
34
35  /**
36   * {@inheritdoc}
37   */
38  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition): array {
39    $definitions = [];
40    // @see FactoryInterface::createInstance()
41    // The ID of the plugin being instantiated.
42    $definitions['plugin_id'] = DataDefinition::create('string')->setRequired(TRUE);
43    // An array of configuration relevant to the plugin instance.
44    $definitions['configuration'] = MapDataDefinition::create();
45
46    return $definitions;
47  }
48
49  /**
50   * {@inheritdoc}
51   */
52  public static function schema(FieldStorageDefinitionInterface $field_definition): array {
53    return [
54      'columns' => [
55        'plugin_id' => [
56          'type' => 'varchar_ascii',
57          'length' => 255,
58        ],
59        'configuration' => [
60          'type' => 'blob',
61          'size' => 'big',
62          'serialize' => TRUE,
63        ],
64      ],
65    ];
66  }
67
68  /**
69   * Get plugin instance.
70   *
71   * @return object
72   *   An instantiated plugin instance.
73   */
74  public function getInstance(): object {
75    $service_id = $this->getSetting('plugin_manager_id');
76    /** @var \Drupal\Component\Plugin\PluginManagerInterface $service */
77    $service = \Drupal::service($service_id);
78
79    return $service->createInstance(
80      $this->get('plugin_id')->getString(),
81      $this->get('configuration')->getValue() ?? [],
82    );
83  }
84
85}

Paths

Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once. Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

PluginItem->defaultFieldSettings
32    ] + parent::defaultFieldSettings();
33  }
PluginItem->getInstance
75    $service_id = $this->getSetting('plugin_manager_id');
76    /** @var \Drupal\Component\Plugin\PluginManagerInterface $service */
77    $service = \Drupal::service($service_id);
78
79    return $service->createInstance(
80      $this->get('plugin_id')->getString(),
81      $this->get('configuration')->getValue() ?? [],
82    );
83  }
PluginItem->propertyDefinitions
38  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition): array {
39    $definitions = [];
40    // @see FactoryInterface::createInstance()
41    // The ID of the plugin being instantiated.
42    $definitions['plugin_id'] = DataDefinition::create('string')->setRequired(TRUE);
43    // An array of configuration relevant to the plugin instance.
44    $definitions['configuration'] = MapDataDefinition::create();
45
46    return $definitions;
47  }
PluginItem->schema
52  public static function schema(FieldStorageDefinitionInterface $field_definition): array {
53    return [
54      'columns' => [
55        'plugin_id' => [
56          'type' => 'varchar_ascii',
57          'length' => 255,
58        ],
59        'configuration' => [
60          'type' => 'blob',
61          'size' => 'big',
62          'serialize' => TRUE,
63        ],
64      ],
65    ];
66  }