View source
<?php
namespace Drupal\diff;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
abstract class FieldDiffBuilderBase extends PluginBase implements FieldDiffBuilderInterface, ContainerFactoryPluginInterface {
protected $configFactory;
protected $entityTypeManager;
protected $entityParser;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, DiffEntityParser $entity_parser) {
$this->entityTypeManager = $entity_type_manager;
$this->entityParser = $entity_parser;
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configuration += $this
->defaultConfiguration();
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('diff.entity_parser'));
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['show_header'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Show field title'),
'#weight' => -5,
'#default_value' => $this->configuration['show_header'],
);
$form['markdown'] = array(
'#type' => 'select',
'#title' => $this
->t('Markdown callback'),
'#default_value' => $this->configuration['markdown'],
'#options' => array(
'drupal_html_to_text' => $this
->t('Drupal HTML to Text'),
'filter_xss' => $this
->t('Filter XSS (some tags)'),
'filter_xss_all' => $this
->t('Filter XSS (all tags)'),
),
'#description' => $this
->t('These provide ways to clean markup tags to make comparisons easier to read.'),
);
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['show_header'] = $form_state
->getValue('show_header');
$this->configuration['markdown'] = $form_state
->getValue('markdown');
}
public function defaultConfiguration() {
return array(
'show_header' => 1,
'markdown' => 'drupal_html_to_text',
);
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this
->defaultConfiguration();
}
public static function isApplicable(FieldStorageDefinitionInterface $field_definition) {
return TRUE;
}
}