You are here

public function ServicesEntityResourceController::checkTextFormatAccess in Services Entity API 7.2

This is a hack to check format access for text fields.

@todo revisit if/when this is handled properly by core.

Parameters

array $values: The raw values passed into the service, keyed by property name.

Throws

ServicesException If user is not authorized to use a provided format.

See also

https://drupal.org/node/2060237

2 calls to ServicesEntityResourceController::checkTextFormatAccess()
ServicesEntityResourceController::create in plugins/services_entity_resource.inc
Implements ServicesResourceControllerInterface::create().
ServicesEntityResourceController::update in plugins/services_entity_resource.inc
Implements ServicesResourceControllerInterface::update().

File

plugins/services_entity_resource.inc, line 295

Class

ServicesEntityResourceController
Generic controller for entity-bases resources.

Code

public function checkTextFormatAccess($values) {

  // Loop through all values looking for text fields.
  foreach ($values as $name => $value) {
    $field = field_info_field($name);
    if ($field && in_array($field['type'], array_keys(text_field_info()))) {
      foreach ($value as $langcode) {
        foreach ($langcode as $item) {
          if (isset($item['format'])) {
            $format = (object) array(
              'format' => $item['format'],
            );
            if (!filter_access($format)) {

              // Fully load the format so we get its label.
              $format = filter_format_load($format->format);
              services_error(t("Not authorized to use format '@format-name' for property '@property-name'.", array(
                '@format-name' => $format->name,
                '@property-name' => $name,
              )), 403);
            }
          }
        }
      }
    }
  }
}