interface MenuLinkInterface implements PluginInspectionInterface, DerivativeInspectionInterface, CacheableDependencyInterface (View source)

Defines an interface for classes providing a type of menu link.

Methods

string
getPluginId()

Gets the plugin_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

string
getBaseId()

Gets the base_plugin_id of the plugin instance.

string|null
getDerivativeId()

Gets the derivative_id of the plugin instance.

string[]
getCacheContexts()

The cache contexts associated with this object.

string[]
getCacheTags()

The cache tags associated with this object.

int
getCacheMaxAge()

The maximum age for which this object may be cached.

int
getWeight()

Returns the weight of the menu link.

string
getTitle()

Returns the localized title to be shown for this link.

string
getDescription()

Returns the description of the menu link.

string
getMenuName()

Returns the menu name of the menu link.

string
getProvider()

Returns the provider (module name) of the menu link.

string
getParent()

Returns the plugin ID of the menu link's parent, or an empty string.

bool
isEnabled()

Returns whether the menu link is enabled (not hidden).

bool
isExpanded()

Returns whether the child menu links should always been shown.

bool
isResettable()

Returns whether this link can be reset.

bool
isTranslatable()

Returns whether this link can be translated.

bool
isDeletable()

Returns whether this link can be deleted.

string
getRouteName()

Returns the route name, if available.

array
getRouteParameters()

Returns the route parameters, if available.

Url
getUrlObject(bool $title_attribute = TRUE)

Returns a URL object containing either the external path or route.

array
getOptions()

Returns the options for this link.

array
getMetaData()

Returns any metadata for this link.

array
updateLink(array $new_definition_values, bool $persist)

Updates the definition values for a menu link.

deleteLink()

Deletes a menu link.

string
getFormClass()

Returns the name of a class that can build an editing form for this link.

Url|null
getDeleteRoute()

Returns route information for a route to delete the menu link.

Url|null
getEditRoute()

Returns route information for a custom edit form for the menu link.

Url|null
getTranslateRoute()

Returns route information for a route to translate the menu link.

Details

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

string getBaseId()

Gets the base_plugin_id of the plugin instance.

Return Value

string

The base_plugin_id of the plugin instance.

string|null getDerivativeId()

Gets the derivative_id of the plugin instance.

Return Value

string|null

The derivative_id of the plugin instance NULL otherwise.

string[] getCacheContexts()

The cache contexts associated with this object.

These identify a specific variation/representation of the object.

Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Return Value

string[]

An array of cache context tokens, used to generate a cache ID.

See also

CacheContextsManager::convertTokensToKeys

string[] getCacheTags()

The cache tags associated with this object.

When this object is modified, these cache tags will be invalidated.

Return Value

string[]

A set of cache tags.

int getCacheMaxAge()

The maximum age for which this object may be cached.

Return Value

int

The maximum time in seconds that this object may be cached.

int getWeight()

Returns the weight of the menu link.

Return Value

int

The weight of the menu link, 0 by default.

string getTitle()

Returns the localized title to be shown for this link.

Return Value

string

The title of the menu link.

string getDescription()

Returns the description of the menu link.

Return Value

string

The description of the menu link.

string getMenuName()

Returns the menu name of the menu link.

Return Value

string

The menu name of the menu link.

string getProvider()

Returns the provider (module name) of the menu link.

Return Value

string

The provider of the menu link.

string getParent()

Returns the plugin ID of the menu link's parent, or an empty string.

Return Value

string

The parent plugin ID.

bool isEnabled()

Returns whether the menu link is enabled (not hidden).

Return Value

bool

TRUE for enabled, FALSE otherwise.

bool isExpanded()

Returns whether the child menu links should always been shown.

Return Value

bool

TRUE for expanded, FALSE otherwise.

bool isResettable()

Returns whether this link can be reset.

In general, only links that store overrides using the menu_link.static.overrides service should return TRUE for this method.

Return Value

bool

TRUE if it can be reset, FALSE otherwise.

bool isTranslatable()

Returns whether this link can be translated.

Return Value

bool

TRUE if the link can be translated, FALSE otherwise.

bool isDeletable()

Returns whether this link can be deleted.

Return Value

bool

TRUE if the link can be deleted, FALSE otherwise.

string getRouteName()

Returns the route name, if available.

Return Value

string

The name of the route this menu link links to.

array getRouteParameters()

Returns the route parameters, if available.

Return Value

array

An array of parameter names and values.

Url getUrlObject(bool $title_attribute = TRUE)

Returns a URL object containing either the external path or route.

Parameters

bool $title_attribute

(optional) If TRUE, add the link description as the title attribute if the description is not empty.

Return Value

Url

A URL object containing either the external path or route.

array getOptions()

Returns the options for this link.

Return Value

array

An associative array of options.

array getMetaData()

Returns any metadata for this link.

Return Value

array

The metadata for the menu link.

Updates the definition values for a menu link.

Depending on the implementation details of the class, not all definition values may be changed. For example, changes to the title of a static link will be discarded.

In general, this method should not be called directly, but will be called automatically from MenuLinkManagerInterface::updateDefinition().

Parameters

array $new_definition_values

The new values for the link definition. This will usually be just a subset of the plugin definition.

bool $persist

TRUE to have the link persist the changed values to any additional storage.

Return Value

array

The plugin definition incorporating any allowed changes.

Deletes a menu link.

In general, this method should not be called directly, but will be called automatically from MenuLinkManagerInterface::removeDefinition().

This method will only delete the link from any additional storage, but not from the plugin.manager.menu.link service.

Exceptions

PluginException

string getFormClass()

Returns the name of a class that can build an editing form for this link.

To instantiate the form class, use an instance of the \Drupal\Core\DependencyInjection\ClassResolverInterface, such as from the class_resolver service. Then call the setMenuLinkInstance() method on the form instance with the menu link plugin instance.

Add a code example. https://www.drupal.org/node/2302849

Return Value

string

A class that implements \Drupal\Core\Menu\Form\MenuLinkFormInterface.

Url|null getDeleteRoute()

Returns route information for a route to delete the menu link.

Return Value

Url|null

A Url object, or NULL if there is no route (e.g. when the link is not deletable).

Url|null getEditRoute()

Returns route information for a custom edit form for the menu link.

Plugins should return a value here if they have a special edit form, or if they need to define additional local tasks, local actions, etc. that are visible from the edit form.

Return Value

Url|null

A Url object, or NULL if there is no route because there is no custom edit route for this instance.

Url|null getTranslateRoute()

Returns route information for a route to translate the menu link.

Return Value

Url|null

A Url object, or NULL if there is no route (e.g. when the link is not translatable).