public function AddToCalendar::getProperValue in Add To Calendar Button (AddEvent.com) 8.4
Same name and namespace in other branches
- 8.3 src/Plugin/Field/FieldFormatter/AddToCalendar.php \Drupal\addtocalendar\Plugin\Field\FieldFormatter\AddToCalendar::getProperValue()
Generate the output appropriate for one add to calendar setting.
Parameters
array $field_setting: The field setting array.
$entity: The entity from which the value is to be returned.
array $options: Provide various options usable to override the data value being return use 'use_raw_value' to return stored value in database. use 'end_date' in case of date range fields.
Return value
string The textual output generated.
1 call to AddToCalendar::getProperValue()
- AddToCalendar::viewValue in src/
Plugin/ Field/ FieldFormatter/ AddToCalendar.php - Generate the output appropriate for one field item.
File
- src/
Plugin/ Field/ FieldFormatter/ AddToCalendar.php, line 123
Class
- AddToCalendar
- Plugin implementation of the 'add_to_calendar' formatter.
Namespace
Drupal\addtocalendar\Plugin\Field\FieldFormatterCode
public function getProperValue(array $field_setting, $entity, array $options = array()) {
$entity_type = $entity
->getEntityTypeId();
// Create token service.
$token_service = \Drupal::token();
$token_options = [
'langcode' => $entity
->language()
->getId(),
'callback' => '',
'clear' => TRUE,
];
switch ($field_setting['field']) {
case 'token':
$value = $field_setting['tokenized'];
$value = $token_service
->replace($value, [
$entity_type => $entity,
], $token_options);
break;
case 'title':
$value = $entity
->getTitle();
break;
default:
$field = $field_setting['field'];
if (isset($options['use_raw_value']) && $options['use_raw_value']) {
$value = strip_tags($entity->{$field}->value);
if (isset($options['end_date']) && strip_tags($entity->{$field}
->getFieldDefinition()
->getType()) == 'daterange') {
$value = strip_tags($entity->{$field}->end_value);
}
}
else {
$value = $entity
->get($field)
->view([
'label' => 'hidden',
]);
$value = strip_tags(render($value));
}
break;
}
return $value;
}