5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8 use Drupal\Core\Plugin\PluginBase;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10 use Drupal\Core\Entity\EntityTypeManagerInterface;
13 * Base class for field diff builder plugins.
15 abstract class FieldDiffBuilderBase extends PluginBase implements FieldDiffBuilderInterface, ContainerFactoryPluginInterface {
18 * Contains the configuration object factory.
20 * @var \Drupal\Core\Config\ConfigFactoryInterface
22 protected $configFactory;
25 * The entity type manager.
27 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
29 protected $entityTypeManager;
34 * @var \Drupal\diff\DiffEntityParser
36 protected $entityParser;
39 * Constructs a FieldDiffBuilderBase object.
41 * @param array $configuration
42 * A configuration array containing information about the plugin instance.
43 * @param string $plugin_id
44 * The plugin_id for the plugin instance.
45 * @param mixed $plugin_definition
46 * The plugin implementation definition.
47 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
48 * The entity type manager.
49 * @param \Drupal\diff\DiffEntityParser $entity_parser
52 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, DiffEntityParser $entity_parser) {
53 $this->entityTypeManager = $entity_type_manager;
54 $this->entityParser = $entity_parser;
55 parent::__construct($configuration, $plugin_id, $plugin_definition);
57 $this->configuration += $this->defaultConfiguration();
63 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
68 $container->get('entity_type.manager'),
69 $container->get('diff.entity_parser')
76 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
77 $form['show_header'] = array(
78 '#type' => 'checkbox',
79 '#title' => $this->t('Show field title'),
81 '#default_value' => $this->configuration['show_header'],
83 $form['markdown'] = array(
85 '#title' => $this->t('Markdown callback'),
86 '#default_value' => $this->configuration['markdown'],
88 'drupal_html_to_text' => $this->t('Drupal HTML to Text'),
89 'filter_xss' => $this->t('Filter XSS (some tags)'),
90 'filter_xss_all' => $this->t('Filter XSS (all tags)'),
92 '#description' => $this->t('These provide ways to clean markup tags to make comparisons easier to read.'),
101 public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
102 // By default an empty validation function is provided.
108 public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
109 $this->configuration['show_header'] = $form_state->getValue('show_header');
110 $this->configuration['markdown'] = $form_state->getValue('markdown');
116 public function defaultConfiguration() {
119 'markdown' => 'drupal_html_to_text',
126 public function getConfiguration() {
127 return $this->configuration;
133 public function setConfiguration(array $configuration) {
134 $this->configuration = $configuration + $this->defaultConfiguration();
140 public function calculateDependencies() {
147 public static function isApplicable(FieldStorageDefinitionInterface $field_definition) {