diff --git a/core/modules/contextual/js/contextual.es6.js b/core/modules/contextual/js/contextual.es6.js index e231e80b95..8c2b1aed40 100644 --- a/core/modules/contextual/js/contextual.es6.js +++ b/core/modules/contextual/js/contextual.es6.js @@ -105,7 +105,7 @@ .find('.contextual'); // Early-return when there's no nesting. - if ($contextuals.length === 1) { + if ($contextuals.length <= 1) { return; } diff --git a/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js index 39daa09973..a23ac66ab3 100644 --- a/core/modules/contextual/js/contextual.js +++ b/core/modules/contextual/js/contextual.js @@ -64,7 +64,7 @@ function adjustIfNestedAndOverlapping($contextual) { var $contextuals = $contextual.parents('.contextual-region').eq(-1).find('.contextual'); - if ($contextuals.length === 1) { + if ($contextuals.length <= 1) { return; } diff --git a/core/modules/quickedit/js/quickedit.es6.js b/core/modules/quickedit/js/quickedit.es6.js index 3fe50076a2..1b1251464b 100644 --- a/core/modules/quickedit/js/quickedit.es6.js +++ b/core/modules/quickedit/js/quickedit.es6.js @@ -359,14 +359,25 @@ // [data-quickedit-entity-id] element's data-quickedit-entity-instance-id // attribute. const entityElementSelector = `[data-quickedit-entity-id="${entityID}"]`; - let entityElement = $(fieldElement).closest(entityElementSelector); + + // const entityElementSelector = `[data-quickedit-entity-id="${entityID}"]`; + // const $entityElement = $(fieldElement).closest(entityElementSelector); + const $entityElement = $(entityElementSelector); + + // If there are no elements returned from `entityElementSelector` + // throw an error. Check the browser console for this message. + if (!$entityElement.length) { + throw `Quick Edit could not associate the rendered entity field markup (with [data-quickedit-field-id="${fieldID}"]) with the corresponding rendered entity markup: no parent DOM node found with [data-quickedit-entity-id="${entityID}"]. This is typically caused by the theme's template for this entity type forgetting to print the attributes.`; + } + let entityElement = $(fieldElement).closest($entityElement); + // In the case of a full entity view page, the entity title is rendered // outside of "the entity DOM node": it's rendered as the page title. So in // this case, we find the lowest common parent element (deepest in the tree) // and consider that the entity element. if (entityElement.length === 0) { - const $lowestCommonParent = $(entityElementSelector).parents().has(fieldElement).first(); - entityElement = $lowestCommonParent.find(entityElementSelector); + const $lowestCommonParent = $entityElement.parents().has(fieldElement).first(); + entityElement = $lowestCommonParent.find($entityElement); } const entityInstanceID = entityElement .get(0) diff --git a/core/modules/quickedit/js/quickedit.js b/core/modules/quickedit/js/quickedit.js index f1e2431fda..a24ac1890d 100644 --- a/core/modules/quickedit/js/quickedit.js +++ b/core/modules/quickedit/js/quickedit.js @@ -159,11 +159,17 @@ var entityID = extractEntityID(fieldID); var entityElementSelector = '[data-quickedit-entity-id="' + entityID + '"]'; - var entityElement = $(fieldElement).closest(entityElementSelector); + + var $entityElement = $(entityElementSelector); + + if (!$entityElement.length) { + throw 'Quick Edit could not associate the rendered entity field markup (with [data-quickedit-field-id="' + fieldID + '"]) with the corresponding rendered entity markup: no parent DOM node found with [data-quickedit-entity-id="' + entityID + '"]. This is typically caused by the theme\'s template for this entity type forgetting to print the attributes.'; + } + var entityElement = $(fieldElement).closest($entityElement); if (entityElement.length === 0) { - var $lowestCommonParent = $(entityElementSelector).parents().has(fieldElement).first(); - entityElement = $lowestCommonParent.find(entityElementSelector); + var $lowestCommonParent = $entityElement.parents().has(fieldElement).first(); + entityElement = $lowestCommonParent.find($entityElement); } var entityInstanceID = entityElement.get(0).getAttribute('data-quickedit-entity-instance-id');