Problem/Motivation

In #2301239: MenuLinkNG part1 (no UI or conversions): plugins (static + MenuLinkContent) + MenuLinkManager + MenuTreeStorage it was noticed that a more specific exception might be useful.
#35 8 and #39 14

Proposed resolution

There might be two distinct kinds.

Remaining tasks

Look at the ones that are there
propose new exceptions

User interface changes

No.

API changes

Just new ones.

Postponed until

#2256497: [meta] Menu Links - New Plan for the Homestretch

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

YesCT’s picture

These look like the ones that Part 1 issue were adding:
core/lib/Drupal/Core/Menu/MenuLinkBase.php
194: throw new PluginException(String::format('Menu link plugin with ID @id does not support deletion', array('@id' => $this->getPluginId())));

core/lib/Drupal/Core/Menu/MenuLinkManager.php
280: throw new PluginException(String::format('Menu link plugin with ID @id does not support deletion', array('@id' => $id)));
348: throw new PluginException(String::format('The ID @id already exists as a plugin definition or is not valid', array('@id' => $id)));
395: throw new PluginException(String::format('Menu link %id is not resetable', array('%id' => $id)));

core/lib/Drupal/Core/Menu/MenuTreeStorage.php
398: throw new PluginException(String::format('The link with ID @id or its children exceeded the maximum depth of @depth', array('@id' => $link['id'], '@depth' => $this->maxDepth())));
1152: throw new PluginException($e->getMessage(), NULL, $e);

xjm’s picture

Issue summary: View changes
Status: Active » Postponed
YesCT’s picture

Issue summary: View changes
cilefen’s picture

Assigned: Unassigned » cilefen
cilefen’s picture

Assigned: cilefen » Unassigned
dawehner’s picture

Status: Postponed » Active

This does not have to be postponed any longer.

cilefen’s picture

Status: Active » Needs review
FileSize
3.95 KB

Trying a PluginNotDeletableException. Is this the sort of thing we want?

dawehner’s picture

Status: Needs review » Needs work

Thank you for working on this issue.

I don't really like "hardcoding" the exception message.

+++ b/core/lib/Drupal/Component/Plugin/Exception/PluginNotDeletableException.php
@@ -0,0 +1,30 @@
+ * @file
+ * Contains \Drupal\Component\Plugin\Exception\PluginNotDeletableException.
+ */
...
+  public function __construct($plugin_id, $message = '', $code = 0, \Exception $previous = NULL) {
+    if (empty($message)) {
+      $message = sprintf("Menu link plugin with ID '%s' does not support deletion.", $plugin_id);
+    }

There is no such concept as deletion of plugins outside of menus

cilefen’s picture

@dawehner: Thank you for reviewing. So, it should be MenuLinkPluginNotDeletableException or something like that? Or, should we go for a MenuLinkPluginException to be more generic.

cilefen’s picture

cilefen’s picture

Status: Needs work » Needs review
FileSize
3.44 KB
5.11 KB

I think MenuLinkManager->addDefinition() could use InvalidPluginDefinitionException.

cilefen’s picture

Should these exceptions live in Drupal\Core\Menu?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Status: Needs review » Needs work

I think this is a good idea.

+++ b/core/lib/Drupal/Core/Menu/MenuLinkBase.php
@@ -179,7 +179,7 @@ public function getTranslateRoute() {
+    throw new PluginNotDeletableException(String::format('Menu link plugin with ID @id does not support deletion', array('@id' => $this->getPluginId())));

+++ b/core/lib/Drupal/Core/Menu/MenuLinkManager.php
@@ -281,7 +283,8 @@ protected function deleteInstance(MenuLinkInterface $instance, $persist) {
+      throw new PluginNotDeletableException(String::format('Menu link plugin with ID @id does not support deletion', array('@id' => $id)));

@@ -349,7 +352,7 @@ public function loadLinksByRoute($route_name, array $route_parameters = array(),
+      throw new InvalidPluginDefinitionException(String::format('The ID @id already exists as a plugin definition or is not valid', array('@id' => $id)));

String::format should be removed and this can just use string interpolation here.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

anmolgoyal74’s picture

Version: 8.9.x-dev » 9.2.x-dev
Status: Needs work » Needs review
FileSize
2.33 KB
4.88 KB

Re-rolled for 9.2.x and addressed #19.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

The interdiff looks confusing but the patch looks great. Setting to rtbc.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

This needs a change record and release notes mention.

<code>
+++ b/core/lib/Drupal/Core/Menu/MenuLinkInterface.php
+++ b/core/lib/Drupal/Core/Menu/MenuLinkInterface.php
@@ -177,7 +177,7 @@ public function updateLink(array $new_definition_values, $persist);

@@ -177,7 +177,7 @@ public function updateLink(array $new_definition_values, $persist);
    * This method will only delete the link from any additional storage, but not
    * from the plugin.manager.menu.link service.
    *
-   * @throws \Drupal\Component\Plugin\Exception\PluginException
+   * @throws \Drupal\Component\Plugin\Exception\PluginNotDeletableException
    *   If the link is not deletable.
    */

Also beyond that, I wonder whether we can actually do this in a minor release - we might need to document that it will throw the more narrow exception in 9.x and make the change itself in 10.x

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.