slug ] ) ) { $value = $attributes[ $key ][ $overrideQuery->slug ][ 'v' ]; } if ( $tokens && is_array( $value ) ) { array_shift( $tokens ); $dot = new Dot( $value ); $value = $dot->get( implode( '.', $tokens ) ); } return $value; } /** * Get the custom value of a specific attribute key. * * @since 1.0.15 * @param string $key The attribute key. * @param array $attributes The attributes array. * @param QueryDTO $query The current query object. * @return mixed */ public static function getCustom( string $key, array $attributes, ?QueryDTO $query = null ) { $custom = false; if ( ! $query ) { $query = Queries::default(); } $overrideQuery = self::overrideTargetQuery( $attributes, $key, $query ); if ( isset( $attributes[ $key ] ) && isset( $attributes[ $key ][ $overrideQuery->slug ] ) && isset( $attributes[ $key ][ $overrideQuery->slug ][ 'custom' ] ) ) { $custom = boolval( $attributes[ $key ][ $overrideQuery->slug ][ 'custom' ] ); } return $custom; } /** * Get the unlink value of a specific attribute key. * * @since 1.0.15 * @param string $key The attribute key. * @param array $attributes The attributes array. * @param QueryDTO $query The current query object. * @return mixed */ public static function getUnlink( string $key, array $attributes, ?QueryDTO $query = null ) { $unlink = false; if ( ! $query ) { $query = Queries::default(); } $overrideQuery = self::overrideTargetQuery( $attributes, $key, $query ); if ( isset( $attributes[ $key ] ) && isset( $attributes[ $key ][ $overrideQuery->slug ] ) && isset( $attributes[ $key ][ $overrideQuery->slug ][ 'unlink' ] ) ) { $unlink = boolval( $attributes[ $key ][ $overrideQuery->slug ][ 'unlink' ] ); } return $unlink; } public static function overrideTargetQuery( array $attributes, string $fieldName, ?QueryDTO $query = null, ?QueryDTO $originalQuery = null ): QueryDTO { if ( ! $query ) { $query = Queries::default(); } if ( ! $originalQuery ) { $originalQuery = $query; } if ( isset( $attributes[$fieldName][$query->slug]['o'] ) && is_string( $attributes[$fieldName][$query->slug]['o'] ) ) { $targetQuery = Queries::getBySlug( $attributes[ $fieldName ][ $query->slug ][ 'o' ] ); if ( ! $targetQuery ) { return Queries::default(); } if ( $targetQuery->slug === $originalQuery->slug ) { return Queries::default(); } $targetQuery = self::overrideTargetQuery( $attributes, $fieldName, $targetQuery, $originalQuery ); if ( ! empty( $attributes[$fieldName][$targetQuery->slug]->o ) && $attributes[$fieldName][$targetQuery->slug]->o === $originalQuery->slug ) { return $originalQuery; } if ( $targetQuery->slug !== $query->slug ) { return self::overrideTargetQuery( $attributes, $fieldName, Queries::getBySlug( $attributes[ $fieldName ][ $query->slug ][ 'o' ] ), $originalQuery ); } else { $query = Queries::default(); } } return $query; } }