protected function ResourceFieldEntity::populatePublicInfoField in RESTful 7.2
Populate public info field with Property API information.
1 call to ResourceFieldEntity::populatePublicInfoField()
- ResourceFieldEntity::setBundle in src/
Plugin/ resource/ Field/ ResourceFieldEntity.php
File
- src/
Plugin/ resource/ Field/ ResourceFieldEntity.php, line 1190 - Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntity
Class
- ResourceFieldEntity
- Class ResourceFieldEntity.
Namespace
Drupal\restful\Plugin\resource\FieldCode
protected function populatePublicInfoField() {
$field_definition = $this
->getDefinition();
$discovery_info = empty($field_definition['discovery']) ? array() : $field_definition['discovery'];
$public_field_info = new PublicFieldInfoEntity($this
->getPublicName(), $this
->getProperty(), $this
->getEntityType(), $this
->getBundle(), $discovery_info);
$this
->setPublicFieldInfo($public_field_info);
if ($field_instance = field_info_instance($this
->getEntityType(), $this
->getProperty(), $this
->getBundle())) {
$public_field_info
->addSectionDefaults('info', array(
'label' => $field_instance['label'],
'description' => $field_instance['description'],
));
$field_info = $this::fieldInfoField($this
->getProperty());
$section_info = array();
$section_info['label'] = empty($field_info['label']) ? NULL : $field_info['label'];
$section_info['description'] = empty($field_info['description']) ? NULL : $field_info['description'];
$public_field_info
->addSectionDefaults('info', $section_info);
$type = $public_field_info instanceof PublicFieldInfoEntityInterface ? $public_field_info
->getFormSchemaAllowedType() : NULL;
$public_field_info
->addSectionDefaults('form_element', array(
'default_value' => isset($field_instance['default_value']) ? $field_instance['default_value'] : NULL,
'type' => $type,
));
// Loading allowed values can be a performance issue, load them only if
// they are not provided in the field definition.
$form_element_info = $public_field_info
->getSection('form_element');
if (!isset($form_element_info['allowed_values'])) {
$allowed_values = $public_field_info instanceof PublicFieldInfoEntityInterface ? $public_field_info
->getFormSchemaAllowedValues() : NULL;
$public_field_info
->addSectionDefaults('form_element', array(
'allowed_values' => $allowed_values,
));
}
}
else {
// Extract the discovery information from the property info.
try {
$property_info = $this
->entityTypeWrapper()
->getPropertyInfo($this
->getProperty());
} catch (\EntityMetadataWrapperException $e) {
return;
}
if (empty($property_info)) {
return;
}
$public_field_info
->addSectionDefaults('data', array(
'type' => $property_info['type'],
'required' => empty($property_info['required']) ? FALSE : $property_info['required'],
));
$public_field_info
->addSectionDefaults('info', array(
'label' => $property_info['label'],
'description' => $property_info['description'],
));
}
}