protected function GeneralEntityReferenceFormatter::sanitizeSettings in Formatter Suite 8
Sanitize settings to insure that they are safe and valid.
@internal Drupal's class hierarchy for plugins and their settings does not include a 'validate' function, like that for other classes with forms. Validation must therefore occur on use, rather than on form submission. @endinternal
3 calls to GeneralEntityReferenceFormatter::sanitizeSettings()
- GeneralEntityReferenceFormatter::settingsForm in src/
Plugin/ Field/ FieldFormatter/ GeneralEntityReferenceFormatter.php - Returns a form to configure settings for the formatter.
- GeneralEntityReferenceFormatter::settingsSummary in src/
Plugin/ Field/ FieldFormatter/ GeneralEntityReferenceFormatter.php - Returns a short summary for the current formatter settings.
- GeneralEntityReferenceFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ GeneralEntityReferenceFormatter.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ GeneralEntityReferenceFormatter.php, line 859
Class
- GeneralEntityReferenceFormatter
- Formats an entity reference as one or more links.
Namespace
Drupal\formatter_suite\Plugin\Field\FieldFormatterCode
protected function sanitizeSettings() {
// Get current settings.
$entityReferenceStyle = $this
->getSetting('entityReferenceStyle');
$showLink = $this
->getSetting('showLink');
$openLinkIn = $this
->getSetting('openLinkIn');
$linkTopic = $this
->getSetting('linkTopic');
$isMultiple = $this->fieldDefinition
->getFieldStorageDefinition()
->isMultiple();
// Get setting defaults.
$defaults = self::defaultSettings();
// Legacy settings.
//
// An earlier version of this formatter supported an entity reference
// style of "titlelink". We now treat this as "title", and $showLink TRUE.
if ($entityReferenceStyle === 'titlelink') {
$entityReferenceStyle = 'title';
$showLink = TRUE;
}
// Sanitize & validate.
//
// While <select> inputs constrain choices to those we define in the
// form, it is possible to hack a form response send other values back.
// So check all <select> choices and use the default when a value is
// empty or unknown.
$entityReferenceStyles = self::getEntityReferenceStyles();
if (empty($entityReferenceStyle) === TRUE || isset($entityReferenceStyles[$entityReferenceStyle]) === FALSE) {
$entityReferenceStyle = $defaults['entityReferenceStyle'];
$this
->setSetting('entityReferenceStyle', $entityReferenceStyle);
}
$openLinkInValues = self::getOpenLinkInValues();
if (empty($openLinkIn) === TRUE || isset($openLinkInValues[$openLinkIn]) === FALSE) {
$openLinkIn = $defaults['openLinkIn'];
$this
->setSetting('openLinkIn', $openLinkIn);
}
$linkTopicValues = self::getLinkTopicValues();
if (empty($linkTopic) === TRUE || isset($linkTopicValues[$linkTopic]) === FALSE) {
$linkTopic = $defaults['linkTopic'];
$this
->setSetting('linkTopic', $linkTopic);
}
// Insure boolean values are boolean.
$showLink = boolval($showLink);
$this
->setSetting('showLink', $showLink);
$listStyle = $this
->getSetting('listStyle');
$listStyles = self::getListStyles();
if ($isMultiple === TRUE) {
if (empty($listStyle) === TRUE || isset($listStyles[$listStyle]) === FALSE) {
$listStyle = $defaults['listStyle'];
$this
->setSetting('listStyle', $listStyle);
}
}
// Classes and custom title text are not sanitized or validated.
// They will be added to the link, with appropriate Xss filtering.
}