You are here

public function ResourceFieldEntityText::preprocess in RESTful 7.2

Massage the value to set according to the format expected by the wrapper.

Parameters

mixed $value: The value passed in the request.

Return value

mixed The value to set using the wrapped property.

Overrides ResourceFieldEntity::preprocess

File

src/Plugin/resource/Field/ResourceFieldEntityText.php, line 18
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntityText.

Class

ResourceFieldEntityText

Namespace

Drupal\restful\Plugin\resource\Field

Code

public function preprocess($value) {

  // Text field. Check if field has an input format.
  $field_info = field_info_field($this
    ->getProperty());

  // If there was no bundle that had the field instance, then return NULL.
  if (!($instance = field_info_instance($this
    ->getEntityType(), $this
    ->getProperty(), $this
    ->getBundle()))) {
    return NULL;
  }
  $return = NULL;
  if ($field_info['cardinality'] == 1) {

    // Single value.
    if (!$instance['settings']['text_processing']) {
      return $value;
    }
    return array(
      'value' => $value,
      // TODO: This is hardcoded! Fix it.
      'format' => 'filtered_html',
    );
  }

  // Multiple values.
  foreach ($value as $delta => $single_value) {
    if (!$instance['settings']['text_processing']) {
      $return[$delta] = $single_value;
    }
    else {
      $return[$delta] = array(
        'value' => $single_value,
        'format' => 'filtered_html',
      );
    }
  }
  return $return;
}