You are here

protected function RestfulEntityBase::getFormSchemaAllowedValues in RESTful 7

Get allowed values for the form schema.

Using Field API's "Options" module to get the allowed values.

Parameters

array $field: The field info array.

Return value

mix | NULL The allowed values or NULL if none found.

1 call to RestfulEntityBase::getFormSchemaAllowedValues()
RestfulEntityBase::getFieldInfoAndFormSchema in plugins/restful/RestfulEntityBase.php
Get the field info, data and form element

File

plugins/restful/RestfulEntityBase.php, line 1377
Contains RestfulEntityBase.

Class

RestfulEntityBase
An abstract implementation of RestfulEntityInterface.

Code

protected function getFormSchemaAllowedValues($field) {
  if (!module_exists('options')) {
    return;
  }
  $entity_type = $this
    ->getEntityType();
  $bundle = $this
    ->getBundle();
  $instance = field_info_instance($entity_type, $field['field_name'], $bundle);
  if (!$this
    ->formSchemaHasAllowedValues($field, $instance)) {

    // Field doesn't have allowed values.
    return;
  }

  // Use Field API's widget to get the allowed values.
  $type = str_replace('options_', '', $instance['widget']['type']);
  $multiple = $field['cardinality'] > 1 || $field['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']] = $bundle;
  }
  $entity = entity_create($entity_type, $values);
  return _options_get_options($field, $instance, $properties, $this
    ->getEntityType(), $entity);
}