Skip to content

Commit 05a0811

Browse files
authored
Issue 137 - Allow formatter to set url_only and url_plain. (#138)
1 parent 4cef02d commit 05a0811

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: src/Plugin/Field/FieldFormatter/AuthorityLinkFormatter.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Drupal\Component\Utility\Unicode;
66
use Drupal\Core\Field\FieldItemListInterface;
7+
use Drupal\Core\Form\FormStateInterface;
78
use Drupal\link\Plugin\Field\FieldFormatter\LinkFormatter;
89

910
/**
@@ -29,6 +30,15 @@ public static function defaultSettings() {
2930
return $settings;
3031
}
3132

33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function settingsForm(array $form, FormStateInterface $form_state) {
37+
$form = parent::settingsForm($form, $form_state);
38+
$form['url_only']['#access'] = $form['url_plain']['#access'] = ($this->getPluginId() == 'authority_formatter_default');
39+
return $form;
40+
}
41+
3242
/**
3343
* {@inheritdoc}
3444
*/
@@ -66,9 +76,13 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
6676
if (!empty($settings['trim_length'])) {
6777
$link_title = Unicode::truncate($link_title, $settings['trim_length'], FALSE, TRUE);
6878
}
79+
if (!empty($settings['url_only']) && empty($settings['url_plain'])) {
80+
$link_title = $url->toString();
81+
}
82+
6983
if (!empty($settings['url_only']) && !empty($settings['url_plain'])) {
7084
$element[$delta] = [
71-
'#plain_text' => $link_title,
85+
'#plain_text' => $url->toString(),
7286
];
7387
if (!empty($item->_attributes)) {
7488

0 commit comments

Comments
 (0)