Skip to content
Snippets Groups Projects

Add field values to query string args

Merged David Gallego requested to merge AddFieldsToQueryInclude into 1.1.x
1 file
+ 26
14
Compare changes
  • Side-by-side
  • Inline
@@ -66,10 +66,10 @@ class QueryInclude extends FieldPluginBase implements ContainerFactoryPluginInte
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition
);
$configuration,
$plugin_id,
$plugin_definition
);
}
/**
@@ -78,16 +78,28 @@ class QueryInclude extends FieldPluginBase implements ContainerFactoryPluginInte
public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
if ($value instanceof EntityInterface && isset($args['args'])) {
$args['args'] = str_replace(
['{id}', '{uuid}', '{bundle}', '{entity_type}', '{langcode}'],
[
$value->id(),
$value->uuid(),
$value->bundle(),
$value->getEntityTypeId(),
$context->getContext('language', $info),
],
$args['args']
);
['{id}', '{uuid}', '{bundle}', '{entity_type}', '{langcode}'],
[
$value->id(),
$value->uuid(),
$value->bundle(),
$value->getEntityTypeId(),
$context->getContext('language', $info),
],
$args['args']
);
if (strstr($args['args'], '{') !== FALSE) {
parse_str($args['args'], $queryArray);
foreach ($queryArray as $key => $arg) {
if (preg_match("/^\{.*\}$/", $arg)) {
$field = str_replace(['{', '}'], '', $arg);
if ($value->hasField($field)) {
$queryArray[$key] = $value->get($field)->getString();
}
}
}
$args['args'] = http_build_query($queryArray);
}
}
yield $args['id'] . (isset($args['args']) ? '?' . $args['args'] : '');
}
Loading