public function WSDataFieldsViews::render in Web Service Data 8
Same name and namespace in other branches
- 2.0.x modules/wsdata_field/src/Plugin/views/field/WSDataFieldsViews.php \Drupal\wsdata_field\Plugin\views\field\WSDataFieldsViews::render()
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
- modules/
wsdata_field/ src/ Plugin/ views/ field/ WSDataFieldsViews.php, line 27
Class
- WSDataFieldsViews
- Field handler for the wsdata fields module.
Namespace
Drupal\wsdata_field\Plugin\views\fieldCode
public function render(ResultRow $values) {
$return = '';
// Based on this field check if the node type has this field.
$field_name = $this->field;
$entity = $values->_entity;
if ($entity
->hasField($field_name)) {
// Load the wsfield config entity.
$wsfield_config = \Drupal::service('entity_type.manager')
->getStorage('wsfield_config')
->load($field_name);
// Get the replacements.
$replacements = is_array($wsfield_config->replacements) ? $wsfield_config->replacements : [];
$wsdata = \Drupal::service('wsdata');
// Create the call based on the wsfield configurations.
$return = $wsdata
->call($wsfield_config->wscall, NULL, $replacements, $wsfield_config->data, [
'langcode' => $entity
->language()
->getId(),
], $wsfield_config->returnToken, [
$entity
->getEntityTypeId() => $entity,
]);
}
return $return;
}