public function FieldChanges::render in Track Field Changes 8
Renders the field.
Parameters
\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.
Return value
string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.
Overrides FieldPluginBase::render
File
- src/
Plugin/ views/ field/ FieldChanges.php, line 21
Class
- FieldChanges
- Field handler to provide field values.
Namespace
Drupal\track_field_changes\Plugin\views\fieldCode
public function render(ResultRow $values) {
$output = '';
if ($this
->getValue($values, 'field_name') == 'log') {
return '';
}
$value = $this
->getValue($values);
$fields = json_decode($value, TRUE);
if (!empty($fields)) {
$output = [];
foreach ($fields as $delta => $field) {
if ($delta === 'target_type') {
continue;
}
foreach ($field as $key => $value) {
if ($key == 'target_id' && !empty($fields['target_type']) && is_numeric($value)) {
$entity = \Drupal::entityTypeManager()
->getStorage($fields['target_type'])
->load($value);
if ($entity) {
$output[] = $entity
->label();
continue;
}
}
$output[] = Html::escape($value);
}
}
$output = implode(' ', $output);
}
return $output;
}