diff --git a/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js index 7f93a15f4d..d73da6afd5 100644 --- a/core/modules/contextual/js/contextual.js +++ b/core/modules/contextual/js/contextual.js @@ -108,7 +108,7 @@ .find('.contextual'); // Early-return when there's no nesting. - if ($contextuals.length === 1) { + if ($contextuals.length <= 1) { return; } diff --git a/core/modules/quickedit/js/quickedit.js b/core/modules/quickedit/js/quickedit.js index 40bdd3e609..445e6b9a1d 100644 --- a/core/modules/quickedit/js/quickedit.js +++ b/core/modules/quickedit/js/quickedit.js @@ -366,14 +366,24 @@ // [data-quickedit-entity-id] element's data-quickedit-entity-instance-id // attribute. var entityElementSelector = '[data-quickedit-entity-id="' + entityID + '"]'; - var entityElement = $(fieldElement).closest(entityElementSelector); + var $entityElement = $(entityElementSelector); + + // If there are no elements returned from `entityElementSelector` + // throw an error. Check the browser console for this message. + if (!$entityElement.length) { + throw Drupal.t('The field [data-quickedit-field-id="@fieldID"] parent attribute [data-quickedit-entity-id] is missing.', { + '@fieldID': fieldID + }); + } + + var 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) { - 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)