Adds settings to Slugify Text Formatter (to capture separator).
This commit is contained in:
@@ -7,6 +7,7 @@ use Drupal\cdesai_tff\SlugifyServiceInterface;
|
||||
use Drupal\cdesai_tff\DesaiTextFormatterBase;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
@@ -71,6 +72,51 @@ class SlugifyTextFormatter extends DesaiTextFormatterBase implements ContainerFa
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultSettings() {
|
||||
$options = parent::defaultSettings();
|
||||
|
||||
$options['tff_separator'] = SlugifyServiceInterface::DEFAULT_SEPARATOR;
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsForm(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::settingsForm($form, $form_state);
|
||||
$defaultSettings = self::defaultSettings();
|
||||
|
||||
$separator = trim($this->getSetting('tff_separator'));
|
||||
$form['tff_separator'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Separator'),
|
||||
'#description' => $this->t('Default if left blank: @default', ['@default' => $defaultSettings['tff_separator']]),
|
||||
'#default_value' => $separator ? $separator : SlugifyServiceInterface::DEFAULT_SEPARATOR,
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsSummary() {
|
||||
$summary = [];
|
||||
|
||||
$separator = trim($this->getSetting('tff_separator'));
|
||||
if ($separator && $separator !== SlugifyServiceInterface::DEFAULT_SEPARATOR) {
|
||||
$summary[] = $this->t('Separator: @value', ['@value' => $separator]);
|
||||
}
|
||||
else {
|
||||
$summary[] = $this->t('Default Separator: @value', ['@value' => SlugifyServiceInterface::DEFAULT_SEPARATOR]);
|
||||
}
|
||||
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -82,7 +128,9 @@ class SlugifyTextFormatter extends DesaiTextFormatterBase implements ContainerFa
|
||||
* @inheritDoc
|
||||
*/
|
||||
function getValue(FieldItemInterface $item) {
|
||||
return $this->slugifyService->convertToSlug($item);
|
||||
$separator = trim($this->getSetting('tff_separator'));
|
||||
return $this->slugifyService->convertToSlug($item, $separator);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user