LinkFieldBuilder.php in Diff 8
File
src/Plugin/diff/Field/LinkFieldBuilder.php
View source
<?php
namespace Drupal\diff\Plugin\diff\Field;
use Drupal\diff\FieldDiffBuilderBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
class LinkFieldBuilder extends FieldDiffBuilderBase {
public function build(FieldItemListInterface $field_items) {
$result = array();
foreach ($field_items as $field_key => $field_item) {
if (!$field_item
->isEmpty()) {
$values = $field_item
->getValue();
if ($this->configuration['compare_title']) {
if (isset($values['title'])) {
$result[$field_key][] = $values['title'];
}
}
if ($this->configuration['compare_uri']) {
if (isset($values['uri'])) {
$result[$field_key][] = $values['uri'];
}
}
}
}
return $result;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['compare_title'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Compare link title'),
'#default_value' => $this->configuration['compare_title'],
);
$form['compare_uri'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Compare URI'),
'#default_value' => $this->configuration['compare_uri'],
);
return parent::buildConfigurationForm($form, $form_state);
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['compare_title'] = $form_state
->getValue('compare_title');
$this->configuration['compare_uri'] = $form_state
->getValue('compare_uri');
parent::submitConfigurationForm($form, $form_state);
}
public function defaultConfiguration() {
$default_configuration = array(
'compare_title' => 0,
'compare_uri' => 1,
);
$default_configuration += parent::defaultConfiguration();
return $default_configuration;
}
}