Disallow deleting an XB-enabled content entity if it's currently the homepage

Created on 13 February 2025, about 2 months ago

Overview

Currently XB is only enabled for the Page content entity type and the article bundle of the Node content entity type. 📌 Allow XB to be used on all node types Active will generalize that.

Hence we need a generic solution to what @lauriii described at #3503412-16: Allow CMS Author to set site's homepage from navigation :

We should not allow deleting the home page. User would have to assign another page as a home page before they could delete it. I'll let you decide if we should implement that here or in another issue.

Proposed resolution

  1. Implement hook_entity_access() to disallow deletion of the given entity if it's currently the homepage (either as its canonical entity route or as its alias).
    (Note that this automatically causes the Drupal admin UI to respect this everywhere, thanks to \Drupal\Core\Entity\EntityListBuilder::getDefaultOperations() checking $entity->access('delete').)
  2. Expand what ApiContentControllers::list() (/xb/api/content/…) returns: include the available operations for each listed entity. IOW: this allows the client to see the result of the "entity operations" hook, aka the result of \Drupal\Core\Entity\EntityListBuilderInterface::getOperations().

⚠️ Users with elevated permissions would still be able to bypass this for some content entity types, such as Node:

    // Only bypass if not a revision operation, to retain compatibility.
    if ($account->hasPermission('bypass node access') && !isset(static::REVISION_OPERATION_MAP[$operation])) {
      $result = AccessResult::allowed()->cachePerPermissions();
      return $return_as_object ? $result : $result->isAllowed();
    }

Out of scope: updating the React UI to only show available operations. That would require the XB API responses to change too, to inform the client which operations

User interface changes

  • The operation in the XB UI for Page entities will not appear if the current page is the homepage
  • The operation will also not appear in Drupal admin UIs for relevant content entities.
📌 Task
Status

Active

Version

0.0

Component

Page builder

Created by

🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

Live updates comments and jobs are added and updated live.
  • Needs product manager review

    It is used to alert the product manager core committer(s) that an issue represents a significant new feature, UI change, or change to the "user experience" of Drupal, and their signoff is needed. If an issue significantly affects the usability of Drupal, use Needs usability review instead (see the governance policy draft for more information).

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024