protected function ResourceFieldEntity::formatterValue in RESTful 7.2
Get value from a field rendered by Drupal field API's formatter.
Parameters
\EntityMetadataWrapper $property_wrapper: The property wrapper. Either \EntityDrupalWrapper or \EntityListWrapper.
\EntityDrupalWrapper $wrapper: The entity wrapper.
Return value
mixed A single or multiple values.
Throws
\Drupal\restful\Exception\ServerConfigurationException
1 call to ResourceFieldEntity::formatterValue()
- ResourceFieldEntity::singleValue in src/
Plugin/ resource/ Field/ ResourceFieldEntity.php - Returns the value for the current single field.
File
- src/
Plugin/ resource/ Field/ ResourceFieldEntity.php, line 500 - Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntity
Class
- ResourceFieldEntity
- Class ResourceFieldEntity.
Namespace
Drupal\restful\Plugin\resource\FieldCode
protected function formatterValue(\EntityMetadataWrapper $property_wrapper, \EntityDrupalWrapper $wrapper) {
$value = NULL;
if (!ResourceFieldEntity::propertyIsField($this
->getProperty())) {
// Property is not a field.
throw new ServerConfigurationException(format_string('@property is not a configurable field, so it cannot be processed using field API formatter', array(
'@property' => $this
->getProperty(),
)));
}
// Get values from the formatter.
$output = field_view_field($this
->getEntityType(), $wrapper
->value(), $this
->getProperty(), $this
->getFormatter());
// Unset the theme, as we just want to get the value from the formatter,
// without the wrapping HTML.
unset($output['#theme']);
if ($property_wrapper instanceof \EntityListWrapper) {
// Multiple values.
foreach (element_children($output) as $delta) {
$value[] = drupal_render($output[$delta]);
}
}
else {
// Single value.
$value = drupal_render($output);
}
return $value;
}