public function PublicFieldInfoEntity::getFormSchemaAllowedValues in RESTful 7.2
Get allowed values for the form schema.
Using Field API's "Options" module to get the allowed values.
Return value
mixed The allowed values or NULL if none found.
Overrides PublicFieldInfoEntityInterface::getFormSchemaAllowedValues
File
- src/
Plugin/ resource/ Field/ PublicFieldInfo/ PublicFieldInfoEntity.php, line 57 - Contains \Drupal\restful\Plugin\resource\Field\PublicFieldInfo\PublicFieldInfoEntity.
Class
Namespace
Drupal\restful\Plugin\resource\Field\PublicFieldInfoCode
public function getFormSchemaAllowedValues() {
if (!module_exists('options')) {
return NULL;
}
$field_name = $this->property;
if (!($field_info = field_info_field($field_name))) {
return NULL;
}
if (!($field_instance = field_info_instance($this->entityType, $field_name, $this->bundle))) {
return NULL;
}
if (!$this::formSchemaHasAllowedValues($field_info, $field_instance)) {
// Field doesn't have allowed values.
return NULL;
}
// Use Field API's widget to get the allowed values.
$type = str_replace('options_', '', $field_instance['widget']['type']);
$multiple = $field_info['cardinality'] > 1 || $field_info['cardinality'] == FIELD_CARDINALITY_UNLIMITED;
// Always pass TRUE for "required" and "has_value", as we don't want to get
// the "none" option.
$required = TRUE;
$has_value = TRUE;
$properties = _options_properties($type, $multiple, $required, $has_value);
// Mock an entity.
$values = array();
$entity_info = $this
->getEntityInfo();
if (!empty($entity_info['entity keys']['bundle'])) {
// Set the bundle of the entity.
$values[$entity_info['entity keys']['bundle']] = $this->bundle;
}
$entity = entity_create($this->entityType, $values);
return _options_get_options($field_info, $field_instance, $properties, $this->entityType, $entity);
}