You are here

protected function ResourceFieldEntity::nestedDottedChildren in RESTful 7.2

Get the children of a query string parameter that apply to the field.

For instance: if the field is 'relatedArticles' and the query string is '?relatedArticles.one.two,articles' it returns array('one.two').

Parameters

string $key: The name of the key: include|fields

Return value

string[] The list of fields.

1 call to ResourceFieldEntity::nestedDottedChildren()
ResourceFieldEntity::singleValue in src/Plugin/resource/Field/ResourceFieldEntity.php
Returns the value for the current single field.

File

src/Plugin/resource/Field/ResourceFieldEntity.php, line 542
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntity

Class

ResourceFieldEntity
Class ResourceFieldEntity.

Namespace

Drupal\restful\Plugin\resource\Field

Code

protected function nestedDottedChildren($key) {

  // Filters are dealt with differently.
  if ($key == 'filter') {
    return $this
      ->nestedDottedFilters();
  }
  $allowed_values = array(
    'include',
    'fields',
  );
  if (!in_array($key, $allowed_values)) {
    return array();
  }
  $input = $this
    ->getRequest()
    ->getParsedInput();
  $limit_values = !empty($input[$key]) ? explode(',', $input[$key]) : array();
  $limit_values = array_filter($limit_values, function ($value) {
    $parts = explode('.', $value);
    return $parts[0] == $this
      ->getPublicName() && $value != $this
      ->getPublicName();
  });
  return array_map(function ($value) {
    return substr($value, strlen($this
      ->getPublicName()) + 1);
  }, $limit_values);
}