XPath can unambiguously use $site/$parent (#14127)
* XPath can unambiguously use $site/$parent * add deprecation notices and obsolete methods * Update deprecation description text/instruction Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Small spelling fix on deprecation description * keep depr. getByQuery and handle legacy usage --------- Co-authored-by: Kalle Macklin <karlmacklin@users.noreply.github.co> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
This commit is contained in:
@@ -555,6 +555,15 @@ public class EntityController : UmbracoAuthorizedJsonController
|
||||
return Ok(returnUrl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an entity by a xpath query - OBSOLETE
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="nodeContextId"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("This will be removed in Umbraco 13. Use GetByXPath instead")]
|
||||
public ActionResult<EntityBasic?>? GetByQuery(string query, int nodeContextId, UmbracoEntityTypes type) => GetByXPath(query, nodeContextId, null, type);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an entity by a xpath query
|
||||
@@ -562,19 +571,16 @@ public class EntityController : UmbracoAuthorizedJsonController
|
||||
/// <param name="query"></param>
|
||||
/// <param name="nodeContextId"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
public ActionResult<EntityBasic?>? GetByQuery(string query, int nodeContextId, UmbracoEntityTypes type)
|
||||
public ActionResult<EntityBasic?>? GetByXPath(string query, int nodeContextId, int? parentId, UmbracoEntityTypes type)
|
||||
{
|
||||
// TODO: Rename this!!! It's misleading, it should be GetByXPath
|
||||
|
||||
|
||||
if (type != UmbracoEntityTypes.Document)
|
||||
{
|
||||
throw new ArgumentException("Get by query is only compatible with entities of type Document");
|
||||
}
|
||||
|
||||
|
||||
var q = ParseXPathQuery(query, nodeContextId);
|
||||
var q = ParseXPathQuery(query, nodeContextId, parentId);
|
||||
IPublishedContent? node = _publishedContentQuery.ContentSingleAtXPath(q);
|
||||
|
||||
if (node == null)
|
||||
@@ -586,10 +592,11 @@ public class EntityController : UmbracoAuthorizedJsonController
|
||||
}
|
||||
|
||||
// PP: Work in progress on the query parser
|
||||
private string ParseXPathQuery(string query, int id) =>
|
||||
private string ParseXPathQuery(string query, int id, int? parentId) =>
|
||||
UmbracoXPathPathSyntaxParser.ParseXPathQuery(
|
||||
query,
|
||||
id,
|
||||
parentId,
|
||||
nodeid =>
|
||||
{
|
||||
IEntitySlim? ent = _entityService.Get(nodeid);
|
||||
|
||||
Reference in New Issue
Block a user