You are here

protected static function Formatter::unprefixInputOptions in RESTful 7.2

Given a prefix, return the allowed fields that apply removing the prefix.

Parameters

bool|string[] $allowed_fields: The list of allowed fields in dot notation.

string $prefix: The prefix used to select the fields and to remove from the front.

Return value

bool|string[] The new allowed fields for the nested sub-request.

3 calls to Formatter::unprefixInputOptions()
Formatter::limitFields in src/Plugin/formatter/Formatter.php
Returns only the allowed fields by filtering out the other ones.
FormatterJsonApi::populateCachePlaceholder in src/Plugin/formatter/FormatterJsonApi.php
Given a field item that contains a cache placeholder render and cache it.
FormatterJsonApi::renormalize in src/Plugin/formatter/FormatterJsonApi.php
Move the embedded resources to the included key.

File

src/Plugin/formatter/Formatter.php, line 302
Contains \Drupal\restful\Plugin\formatter\Formatter

Class

Formatter
Class Formatter.

Namespace

Drupal\restful\Plugin\formatter

Code

protected static function unprefixInputOptions($allowed_fields, $prefix) {
  if ($allowed_fields === FALSE) {
    return FALSE;
  }
  $closure_unprefix = function ($field_limit) use ($prefix) {
    if ($field_limit == $prefix) {
      return NULL;
    }
    $pos = strpos($field_limit, $prefix . '.');

    // Remove the prefix from the $field_limit.
    return $pos === 0 ? substr($field_limit, strlen($prefix . '.')) : NULL;
  };
  return array_filter(array_map($closure_unprefix, $allowed_fields));
}