getModel()->getSourceClass(); // Only site trees have the get_by_link capability if ($class !== SiteTree::class && !is_subclass_of($class, SiteTree::class)) { return; } $singleFieldName = $this->config()->get('single_field_name'); $listFieldName = $this->config()->get('list_field_name'); $fieldName = $query->isList() ? $listFieldName : $singleFieldName; $type = $query->isList() ? '[String]' : 'String'; $query->addArg($fieldName, $type); $query->addResolverAfterware( $config['resolver'] ?? static::config()->get('resolver') ); } /** * @param array $context * @return callable */ public static function applyLinkFilter($obj, array $args, array $context, ResolveInfo $info) { $singleFieldName = static::config()->get('single_field_name'); $listFieldName = static::config()->get('list_field_name'); $filterLink = $args['filter'][$singleFieldName] ?? ($args['filter'][$listFieldName] ?? null); $argLink = $args[$singleFieldName] ?? ($args[$listFieldName] ?? null); $linkData = $filterLink ?: $argLink; if (!$linkData) { return $obj; } // Normalise to an array for both cases. The readOne operation will get // ->first() run on it by the firstResult plugin. $links = is_array($linkData) ? $linkData : [$linkData]; $result = ArrayList::create(); foreach ($links as $link) { $page = SiteTree::get_by_link($link); if ($page) { $result->push($page); } } return $result; } }