3 namespace Drupal\Core\Menu;
5 use Drupal\Component\Plugin\PluginInspectionInterface;
6 use Drupal\Component\Plugin\DerivativeInspectionInterface;
7 use Drupal\Core\Cache\CacheableDependencyInterface;
10 * Defines an interface for classes providing a type of menu link.
12 interface MenuLinkInterface extends PluginInspectionInterface, DerivativeInspectionInterface, CacheableDependencyInterface {
15 * Returns the weight of the menu link.
18 * The weight of the menu link, 0 by default.
20 public function getWeight();
23 * Returns the localized title to be shown for this link.
26 * The title of the menu link.
28 public function getTitle();
31 * Returns the description of the menu link.
34 * The description of the menu link.
36 public function getDescription();
39 * Returns the menu name of the menu link.
42 * The menu name of the menu link.
44 public function getMenuName();
47 * Returns the provider (module name) of the menu link.
50 * The provider of the menu link.
52 public function getProvider();
55 * Returns the plugin ID of the menu link's parent, or an empty string.
58 * The parent plugin ID.
60 public function getParent();
63 * Returns whether the menu link is enabled (not hidden).
66 * TRUE for enabled, FALSE otherwise.
68 public function isEnabled();
71 * Returns whether the child menu links should always been shown.
74 * TRUE for expanded, FALSE otherwise.
76 public function isExpanded();
79 * Returns whether this link can be reset.
81 * In general, only links that store overrides using the
82 * menu_link.static.overrides service should return TRUE for this method.
85 * TRUE if it can be reset, FALSE otherwise.
87 public function isResettable();
90 * Returns whether this link can be translated.
93 * TRUE if the link can be translated, FALSE otherwise.
95 public function isTranslatable();
98 * Returns whether this link can be deleted.
101 * TRUE if the link can be deleted, FALSE otherwise.
103 public function isDeletable();
106 * Returns the route name, if available.
109 * The name of the route this menu link links to.
111 public function getRouteName();
114 * Returns the route parameters, if available.
117 * An array of parameter names and values.
119 public function getRouteParameters();
122 * Returns a URL object containing either the external path or route.
124 * @param bool $title_attribute
125 * (optional) If TRUE, add the link description as the title attribute if
126 * the description is not empty.
128 * @return \Drupal\Core\Url
129 * A URL object containing either the external path or route.
131 public function getUrlObject($title_attribute = TRUE);
134 * Returns the options for this link.
137 * An associative array of options.
139 public function getOptions();
142 * Returns any metadata for this link.
145 * The metadata for the menu link.
147 public function getMetaData();
150 * Updates the definition values for a menu link.
152 * Depending on the implementation details of the class, not all definition
153 * values may be changed. For example, changes to the title of a static link
156 * In general, this method should not be called directly, but will be called
157 * automatically from MenuLinkManagerInterface::updateDefinition().
159 * @param array $new_definition_values
160 * The new values for the link definition. This will usually be just a
161 * subset of the plugin definition.
162 * @param bool $persist
163 * TRUE to have the link persist the changed values to any additional
167 * The plugin definition incorporating any allowed changes.
169 public function updateLink(array $new_definition_values, $persist);
172 * Deletes a menu link.
174 * In general, this method should not be called directly, but will be called
175 * automatically from MenuLinkManagerInterface::removeDefinition().
177 * This method will only delete the link from any additional storage, but not
178 * from the plugin.manager.menu.link service.
180 * @throws \Drupal\Component\Plugin\Exception\PluginException
181 * If the link is not deletable.
183 public function deleteLink();
186 * Returns the name of a class that can build an editing form for this link.
188 * To instantiate the form class, use an instance of the
189 * \Drupal\Core\DependencyInjection\ClassResolverInterface, such as from the
190 * class_resolver service. Then call the setMenuLinkInstance() method on the
191 * form instance with the menu link plugin instance.
193 * @todo Add a code example. https://www.drupal.org/node/2302849
196 * A class that implements \Drupal\Core\Menu\Form\MenuLinkFormInterface.
198 public function getFormClass();
201 * Returns route information for a route to delete the menu link.
203 * @return \Drupal\Core\Url|null
204 * A Url object, or NULL if there is no route (e.g. when the link is not
207 public function getDeleteRoute();
210 * Returns route information for a custom edit form for the menu link.
212 * Plugins should return a value here if they have a special edit form, or if
213 * they need to define additional local tasks, local actions, etc. that are
214 * visible from the edit form.
216 * @return \Drupal\Core\Url|null
217 * A Url object, or NULL if there is no route because there is no custom
218 * edit route for this instance.
220 public function getEditRoute();
223 * Returns route information for a route to translate the menu link.
225 * @return \Drupal\Core\Url|null
226 * A Url object, or NULL if there is no route (e.g. when the link is not
229 public function getTranslateRoute();